@@ -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}
0 commit comments