Skip to content

Commit cba9cd9

Browse files
Merge pull request #320 from daniellienert/task/remove-mapping-fallback
!!! TASK: Remove fallback for fields with string mapping
2 parents 45e0975 + a2cb1d1 commit cba9cd9

4 files changed

Lines changed: 5 additions & 89 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/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

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)