Skip to content

Commit a2cb1d1

Browse files
committed
!!! TASK: Remove fallback for fields with string mapping
The field type string was removed with Elasticsearch 5. The adapter internally mapped string to either keyword or text depending on the not_analyzed keyword. This mapping is removed now. Please adjust your configuration.
1 parent 51b889a commit a2cb1d1

6 files changed

Lines changed: 19 additions & 117 deletions

File tree

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
declare(strict_types=1);
43

54
namespace Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\Version6\Mapping;
@@ -23,12 +22,8 @@
2322
use Neos\Error\Messages\Result;
2423
use Neos\Error\Messages\Warning;
2524
use Neos\Flow\Annotations as Flow;
26-
use Neos\Flow\Configuration\Exception\InvalidConfigurationTypeException;
27-
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
2825

2926
/**
30-
* NodeTypeMappingBuilder for Elasticsearch version 5.x
31-
*
3227
* @Flow\Scope("singleton")
3328
*/
3429
class NodeTypeMappingBuilder extends AbstractNodeTypeMappingBuilder
@@ -39,20 +34,6 @@ class NodeTypeMappingBuilder extends AbstractNodeTypeMappingBuilder
3934
*/
4035
protected $nodeTypeIndexingConfiguration;
4136

42-
/**
43-
* Called by the Flow object framework after creating the object and resolving all dependencies.
44-
*
45-
* @param integer $cause Creation cause
46-
* @throws InvalidConfigurationTypeException
47-
*/
48-
public function initializeObject($cause): void
49-
{
50-
parent::initializeObject($cause);
51-
52-
if ($cause === ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED) {
53-
$this->migrateConfigurationForElasticVersion6($this->defaultConfigurationPerType);
54-
}
55-
}
5637

5738
/**
5839
* Builds a Mapping Collection from the configured node types
@@ -82,15 +63,13 @@ public function buildMappingInformation(Index $index): MappingCollection
8263
$fullConfiguration = $nodeType->getFullConfiguration();
8364
if (isset($fullConfiguration['search']['elasticSearchMapping'])) {
8465
$fullMapping = $fullConfiguration['search']['elasticSearchMapping'];
85-
$this->migrateConfigurationForElasticVersion6($fullMapping);
8666
$mapping->setFullMapping($fullMapping);
8767
}
8868

8969
foreach ($nodeType->getProperties() as $propertyName => $propertyConfiguration) {
9070
if (isset($propertyConfiguration['search']['elasticSearchMapping'])) {
9171
if (is_array($propertyConfiguration['search']['elasticSearchMapping'])) {
9272
$propertyMapping = $propertyConfiguration['search']['elasticSearchMapping'];
93-
$this->migrateConfigurationForElasticVersion6($propertyMapping);
9473
$mapping->setPropertyByPath($propertyName, $propertyMapping);
9574
}
9675
} elseif (isset($propertyConfiguration['type'], $this->defaultConfigurationPerType[$propertyConfiguration['type']]['elasticSearchMapping'])) {
@@ -107,61 +86,4 @@ public function buildMappingInformation(Index $index): MappingCollection
10786

10887
return $mappings;
10988
}
110-
111-
/**
112-
* @param array $mapping
113-
* @return void
114-
*/
115-
protected function migrateConfigurationForElasticVersion6(array &$mapping): void
116-
{
117-
$this->adjustStringTypeMapping($mapping);
118-
}
119-
120-
/**
121-
* Adjust the mapping for string to text or keyword as needed.
122-
*
123-
* This is used to ease moving from ES 1.x and 2.x to 5.x by migrating the
124-
* mapping like this:
125-
*
126-
* | 2.x | 5.x |
127-
* |-------------------------------------------|----------------------------------|
128-
* | "type": "string", "index": "no" | "type": "text", "index": false |
129-
* | "type": "string", "index": "analyzed" | "type": "text", "index": true |
130-
* | "type": "string", "index": "not_analyzed" | "type": "keyword", "index": true |
131-
*
132-
* @param array &$mapping
133-
* @return void
134-
*/
135-
protected function adjustStringTypeMapping(array &$mapping): void
136-
{
137-
$adjustStringTypeMapping = function (&$item) {
138-
if (isset($item['type']) && $item['type'] === 'string') {
139-
if (isset($item['index'])) {
140-
if ($item['index'] === 'not_analyzed') {
141-
$item['type'] = 'keyword';
142-
$item['index'] = true;
143-
unset($item['analyzer']);
144-
} elseif ($item['index'] === 'no') {
145-
$item['type'] = 'text';
146-
$item['index'] = false;
147-
} elseif ($item['index'] === 'analyzed') {
148-
$item['type'] = 'text';
149-
$item['index'] = true;
150-
}
151-
} else {
152-
$item['type'] = 'keyword';
153-
$item['index'] = true;
154-
}
155-
}
156-
};
157-
158-
$adjustStringTypeMapping($mapping);
159-
160-
foreach ($mapping as &$item) {
161-
if (is_array($item)) {
162-
$adjustStringTypeMapping($mapping);
163-
$this->adjustStringTypeMapping($item);
164-
}
165-
}
166-
}
16789
}

Configuration/NodeTypes.yaml

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,25 @@
66
'__identifier':
77
search:
88
elasticSearchMapping:
9-
type: string
10-
index: not_analyzed
9+
type: keyword
1110
indexing: '${node.identifier}'
1211

1312
'__workspace':
1413
search:
1514
elasticSearchMapping:
16-
type: string
17-
index: not_analyzed
15+
type: keyword
1816
indexing: '${node.context.workspace.name}'
1917

2018
'__path':
2119
search:
2220
elasticSearchMapping:
23-
type: string
24-
index: not_analyzed
21+
type: keyword
2522
indexing: '${node.path}'
2623

2724
'__parentPath':
2825
search:
2926
elasticSearchMapping:
30-
type: string
31-
index: not_analyzed
27+
type: keyword
3228
# we index *all* parent paths as separate tokens to allow for efficient searching without a prefix query
3329
indexing: '${Indexing.buildAllPathPrefixes(node.parentPath)}'
3430

@@ -47,8 +43,7 @@
4743
'__typeAndSupertypes':
4844
search:
4945
elasticSearchMapping:
50-
type: string
51-
index: not_analyzed
46+
type: keyword
5247
indexing: '${Indexing.extractNodeTypeNamesAndSupertypes(node.nodeType)}'
5348

5449
'_lastModificationDateTime':
@@ -105,8 +100,7 @@
105100
'uriPathSegment':
106101
search:
107102
elasticSearchMapping:
108-
type: string
109-
index: not_analyzed
103+
type: keyword
110104
title:
111105
search:
112106
fulltextExtractor: ${Indexing.extractInto('h1', value)}
@@ -123,32 +117,25 @@
123117
type: object
124118
properties:
125119
'h1':
126-
type: string
127-
index: analyzed
120+
type: text
128121
boost: 20
129122
'h2':
130-
type: string
131-
index: analyzed
123+
type: text
132124
boost: 12
133125
'h3':
134-
type: string
135-
index: analyzed
126+
type: text
136127
boost: 10
137128
'h4':
138-
type: string
139-
index: analyzed
129+
type: text
140130
boost: 5
141131
'h5':
142-
type: string
143-
index: analyzed
132+
type: text
144133
boost: 3
145134
'h6':
146-
type: string
147-
index: analyzed
135+
type: text
148136
boost: 2
149137
'text':
150-
type: string
151-
index: analyzed
138+
type: text
152139
boost: 1
153140
'_hiddenInIndex':
154141
search:

Configuration/Settings.Neos.ContentRepository.Search.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Neos:
1717

1818
string:
1919
elasticSearchMapping:
20-
type: string
20+
type: keyword
2121

2222
boolean:
2323
elasticSearchMapping:
@@ -43,10 +43,8 @@ Neos:
4343

4444
'references':
4545
elasticSearchMapping:
46-
type: string # an array of strings, to be precise
47-
index: not_analyzed
46+
type: keyword # an array of keywords, to be precise
4847

4948
'reference':
5049
elasticSearchMapping:
51-
type: string
52-
index: not_analyzed
50+
type: keyword

Configuration/Testing/NodeTypes.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@
1616
type: string
1717
search:
1818
elasticSearchMapping:
19-
type: string
20-
index: analyzed
19+
type: text

Documentation/ElasticMapping-5.x.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
# Mapping for Elasticsearch 5.x
1+
# Mapping for Elasticsearch 5.x+
22

33
In contrast to earlier versions, Elasticsearch has deprecated the `string` type
44
in version 5. This affects the `index` setting on a field as well.
55

6-
This package tries to adjust the mapping on-the-fly so you may not need to
7-
adjust anything, but in certain cases knowing what would be correct might help.
8-
96
## `string` is dead, long live strings
107

118
The `string` type was used for different things, namely analyzed content to

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,7 @@ for all your filterable properties, or else filtering won't work on them properl
601601
defaultValue: ''
602602
search:
603603
elasticSearchMapping:
604-
type: "string"
605-
index: 'not_analyzed'
604+
type: keyword
606605
```
607606

608607
**Note:** When using Elasticsearch 5.x the mapping needs to be adjusted in a different way.

0 commit comments

Comments
 (0)