@@ -39,7 +39,7 @@ public function initializeObject($cause)
3939 {
4040 parent ::initializeObject ($ cause );
4141 if ($ cause === ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED ) {
42- $ this ->adjustStringTypeMapping ($ this ->defaultConfigurationPerType );
42+ $ this ->migrateConfigurationForElasticVersion5 ($ this ->defaultConfigurationPerType );
4343 }
4444 }
4545
@@ -66,7 +66,7 @@ public function buildMappingInformation(Index $index)
6666 $ fullConfiguration = $ nodeType ->getFullConfiguration ();
6767 if (isset ($ fullConfiguration ['search ' ]['elasticSearchMapping ' ])) {
6868 $ fullMapping = $ fullConfiguration ['search ' ]['elasticSearchMapping ' ];
69- $ this ->adjustStringTypeMapping ($ fullMapping );
69+ $ this ->migrateConfigurationForElasticVersion5 ($ fullMapping );
7070 $ mapping ->setFullMapping ($ fullMapping );
7171 }
7272
@@ -86,7 +86,7 @@ public function buildMappingInformation(Index $index)
8686 if (isset ($ propertyConfiguration ['search ' ]) && isset ($ propertyConfiguration ['search ' ]['elasticSearchMapping ' ])) {
8787 if (is_array ($ propertyConfiguration ['search ' ]['elasticSearchMapping ' ])) {
8888 $ propertyMapping = $ propertyConfiguration ['search ' ]['elasticSearchMapping ' ];
89- $ this ->adjustStringTypeMapping ($ propertyMapping );
89+ $ this ->migrateConfigurationForElasticVersion5 ($ propertyMapping );
9090 $ mapping ->setPropertyByPath ($ propertyName , $ propertyMapping );
9191 }
9292 } elseif (isset ($ propertyConfiguration ['type ' ]) && isset ($ this ->defaultConfigurationPerType [$ propertyConfiguration ['type ' ]]['elasticSearchMapping ' ])) {
@@ -104,6 +104,44 @@ public function buildMappingInformation(Index $index)
104104 return $ mappings ;
105105 }
106106
107+ /**
108+ * @param array $mapping
109+ * @return void
110+ */
111+ protected function migrateConfigurationForElasticVersion5 (array &$ mapping )
112+ {
113+ $ this ->migrateIncludeInAllToCopyTo ($ mapping );
114+ $ this ->adjustStringTypeMapping ($ mapping );
115+ }
116+
117+ /**
118+ * include_in_all is deprecated with elasticsearch 5.x and raises
119+ * warnings on index creation
120+ *
121+ * @param array $mapping
122+ * @return void
123+ */
124+ protected function migrateIncludeInAllToCopyTo (array &$ mapping )
125+ {
126+ $ migrateIncludeInAll = function (&$ mapping ) {
127+ if (isset ($ mapping ['include_in_all ' ])) {
128+ if ((bool )$ mapping ['include_in_all ' ] === true ) {
129+ $ mapping ['copy_to ' ] = '_all ' ;
130+ }
131+ unset($ mapping ['include_in_all ' ]);
132+ }
133+ };
134+
135+ $ migrateIncludeInAll ($ mapping );
136+
137+ foreach ($ mapping as &$ item ) {
138+ if (is_array ($ item )) {
139+ $ migrateIncludeInAll ($ mapping );
140+ $ this ->migrateIncludeInAllToCopyTo ($ item );
141+ }
142+ }
143+ }
144+
107145 /**
108146 * Adjust the mapping for string to text or keyword as needed.
109147 *
@@ -121,11 +159,7 @@ public function buildMappingInformation(Index $index)
121159 */
122160 protected function adjustStringTypeMapping (array &$ mapping )
123161 {
124- foreach ($ mapping as &$ item ) {
125- if (!is_array ($ item )) {
126- continue ;
127- }
128-
162+ $ adjustStringTypeMapping = function (&$ item ) {
129163 if (isset ($ item ['type ' ]) && $ item ['type ' ] === 'string ' ) {
130164 if (isset ($ item ['index ' ]) && $ item ['index ' ] === 'not_analyzed ' ) {
131165 $ item ['type ' ] = 'keyword ' ;
@@ -142,8 +176,15 @@ protected function adjustStringTypeMapping(array &$mapping)
142176 $ item ['index ' ] = true ;
143177 }
144178 }
179+ };
145180
146- $ this ->adjustStringTypeMapping ($ item );
181+ $ adjustStringTypeMapping ($ mapping );
182+
183+ foreach ($ mapping as &$ item ) {
184+ if (is_array ($ item )) {
185+ $ adjustStringTypeMapping ($ mapping );
186+ $ this ->adjustStringTypeMapping ($ item );
187+ }
147188 }
148189 }
149190}
0 commit comments