@@ -40,6 +40,16 @@ class ElasticConfigureTask extends BuildTask
4040 */
4141 protected $ service ;
4242
43+ /**
44+ * DBHTML and DBText etc. should never be made sortable
45+ * It doesn't make sense for large text objects
46+ * @var string[]
47+ */
48+ private static $ unSsortables = [
49+ 'HTML ' ,
50+ 'Text '
51+ ];
52+
4353 /**
4454 * @throws NotFoundExceptionInterface
4555 */
@@ -108,7 +118,6 @@ protected function configureIndex($instance): Elasticsearch
108118 {
109119 $ indexName = $ instance ->getIndexName ();
110120
111-
112121 $ instanceConfig = $ this ->createConfigForIndex ($ instance );
113122
114123 $ mappings = $ this ->convertForJSON ($ instanceConfig );
@@ -123,14 +132,15 @@ protected function configureIndex($instance): Elasticsearch
123132 $ msg = sprintf ($ msg , 'Updating ' , $ indexName );
124133 DB ::alteration_message ($ msg );
125134 $ this ->getLogger ()->info ($ msg );
135+
126136 return $ client ->indices ()->putMapping ($ body );
127- } else {
128- $ body ['body ' ]['mappings ' ] = $ mappings ;
129- $ msg = sprintf ($ msg , 'Creating ' , $ indexName );
130- DB ::alteration_message ($ msg );
131- $ this ->getLogger ()->info ($ msg );
132- return $ client ->indices ()->create ($ body );
133137 }
138+ $ body ['body ' ]['mappings ' ] = $ mappings ;
139+ $ msg = sprintf ($ msg , 'Creating ' , $ indexName );
140+ DB ::alteration_message ($ msg );
141+ $ this ->getLogger ()->info ($ msg );
142+
143+ return $ client ->indices ()->create ($ body );
134144 }
135145
136146 /**
@@ -171,6 +181,13 @@ protected function convertForJSON($config)
171181 $ base [$ conf ['name ' ]] = [
172182 'type ' => $ typeMap [$ conf ['type ' ] ?? '* ' ]
173183 ];
184+ $ shouldHold = true ;
185+ foreach (self ::$ unSsortables as $ unSortable ) {
186+ $ shouldHold = !str_contains ($ conf ['type ' ], $ unSortable ) && $ shouldHold ;
187+ }
188+ if ($ shouldHold && $ typeMap [$ conf ['type ' ]] === 'text ' ) {
189+ $ base [$ conf ['name ' ]]['fielddata ' ] = true ;
190+ }
174191 }
175192
176193 return ['properties ' => $ base ];
0 commit comments