Skip to content

Commit c5514d1

Browse files
committed
TASK: Merge branch '3.0' into 4.0
2 parents b6b533e + 703372e commit c5514d1

2 files changed

Lines changed: 52 additions & 11 deletions

File tree

Classes/Driver/Version5/Mapping/NodeTypeMappingBuilder.php

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function initializeObject($cause)
3737
{
3838
parent::initializeObject($cause);
3939
if ($cause === ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED) {
40-
$this->adjustStringTypeMapping($this->defaultConfigurationPerType);
40+
$this->migrateConfigurationForElasticVersion5($this->defaultConfigurationPerType);
4141
}
4242
}
4343

@@ -64,7 +64,7 @@ public function buildMappingInformation(Index $index)
6464
$fullConfiguration = $nodeType->getFullConfiguration();
6565
if (isset($fullConfiguration['search']['elasticSearchMapping'])) {
6666
$fullMapping = $fullConfiguration['search']['elasticSearchMapping'];
67-
$this->adjustStringTypeMapping($fullMapping);
67+
$this->migrateConfigurationForElasticVersion5($fullMapping);
6868
$mapping->setFullMapping($fullMapping);
6969
}
7070

@@ -84,7 +84,7 @@ public function buildMappingInformation(Index $index)
8484
if (isset($propertyConfiguration['search']) && isset($propertyConfiguration['search']['elasticSearchMapping'])) {
8585
if (is_array($propertyConfiguration['search']['elasticSearchMapping'])) {
8686
$propertyMapping = $propertyConfiguration['search']['elasticSearchMapping'];
87-
$this->adjustStringTypeMapping($propertyMapping);
87+
$this->migrateConfigurationForElasticVersion5($propertyMapping);
8888
$mapping->setPropertyByPath($propertyName, $propertyMapping);
8989
}
9090
} elseif (isset($propertyConfiguration['type']) && isset($this->defaultConfigurationPerType[$propertyConfiguration['type']]['elasticSearchMapping'])) {
@@ -102,6 +102,44 @@ public function buildMappingInformation(Index $index)
102102
return $mappings;
103103
}
104104

105+
/**
106+
* @param array $mapping
107+
* @return void
108+
*/
109+
protected function migrateConfigurationForElasticVersion5(array &$mapping)
110+
{
111+
$this->migrateIncludeInAllToCopyTo($mapping);
112+
$this->adjustStringTypeMapping($mapping);
113+
}
114+
115+
/**
116+
* include_in_all is deprecated with elasticsearch 5.x and raises
117+
* warnings on index creation
118+
*
119+
* @param array $mapping
120+
* @return void
121+
*/
122+
protected function migrateIncludeInAllToCopyTo(array &$mapping)
123+
{
124+
$migrateIncludeInAll = function (&$mapping) {
125+
if (isset($mapping['include_in_all'])) {
126+
if ((bool)$mapping['include_in_all'] === true) {
127+
$mapping['copy_to'] = '_all';
128+
}
129+
unset($mapping['include_in_all']);
130+
}
131+
};
132+
133+
$migrateIncludeInAll($mapping);
134+
135+
foreach ($mapping as &$item) {
136+
if (is_array($item)) {
137+
$migrateIncludeInAll($mapping);
138+
$this->migrateIncludeInAllToCopyTo($item);
139+
}
140+
}
141+
}
142+
105143
/**
106144
* Adjust the mapping for string to text or keyword as needed.
107145
*
@@ -119,11 +157,7 @@ public function buildMappingInformation(Index $index)
119157
*/
120158
protected function adjustStringTypeMapping(array &$mapping)
121159
{
122-
foreach ($mapping as &$item) {
123-
if (!is_array($item)) {
124-
continue;
125-
}
126-
160+
$adjustStringTypeMapping = function (&$item) {
127161
if (isset($item['type']) && $item['type'] === 'string') {
128162
if (isset($item['index']) && $item['index'] === 'not_analyzed') {
129163
$item['type'] = 'keyword';
@@ -140,8 +174,15 @@ protected function adjustStringTypeMapping(array &$mapping)
140174
$item['index'] = true;
141175
}
142176
}
177+
};
143178

144-
$this->adjustStringTypeMapping($item);
179+
$adjustStringTypeMapping($mapping);
180+
181+
foreach ($mapping as &$item) {
182+
if (is_array($item)) {
183+
$adjustStringTypeMapping($mapping);
184+
$this->adjustStringTypeMapping($item);
185+
}
145186
}
146187
}
147188
}

Documentation/ElasticConfiguration-5.x.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ But the following can make your life easier:
88
# the following settings secure your cluster
99
cluster.name: [PUT_YOUR_CUSTOM_NAME_HERE]
1010
node.name: [PUT_YOUR_CUSTOM_NAME_HERE]
11-
network.host: 127.0.0.1
11+
network.host: _local_
1212
```
1313

1414
**Note:** When using Elasticsearch 5.x changes to the mapping may be needed.
15-
More information on the [mapping in ElasticSearch 5.x](Documentation/ElasticMapping-5.x.md).
15+
More information on the [mapping in ElasticSearch 5.x](ElasticMapping-5.x.md).

0 commit comments

Comments
 (0)