@@ -36,6 +36,10 @@ class ElasticConfigureTask extends BuildTask
3636{
3737 use LoggerTrait;
3838
39+ /**
40+ * @var bool[]
41+ */
42+ public $ result ;
3943 /**
4044 * @var string URLSegment
4145 */
@@ -76,7 +80,7 @@ public function __construct()
7680 * Run the config
7781 *
7882 * @param HTTPRequest $request
79- * @return void|array
83+ * @return void
8084 * @throws NotFoundExceptionInterface
8185 */
8286 public function run ($ request )
@@ -114,7 +118,7 @@ public function run($request)
114118 $ this ->extend ('onAfterElasticConfigureTask ' );
115119
116120 if ($ request ->getVar ('istest ' )) {
117- return $ result ;
121+ $ this -> result = $ result ;
118122 }
119123 }
120124
@@ -135,25 +139,22 @@ protected function configureIndex($instance): Elasticsearch
135139
136140 $ mappings = $ this ->convertForJSON ($ instanceConfig );
137141
138- $ body ['index ' ] = $ indexName ;
142+ $ body = ['index ' => $ indexName] ;
139143 $ client = $ this ->service ->getClient ();
140144
141145 $ method = $ this ->getMethod ($ instance );
142146 $ msg = "%s index %s " ;
143- if ($ method === 'update ' ) {
144- $ body ['body ' ] = $ mappings ;
145- $ msg = sprintf ($ msg , 'Updating ' , $ indexName );
146- DB ::alteration_message ($ msg );
147- $ this ->getLogger ()->info ($ msg );
148-
149- return $ client ->indices ()->putMapping ($ body );
147+ $ msgType = 'Updating ' ;
148+ if ($ method === 'create ' ) {
149+ $ mappings = ['mappings ' => $ mappings ];
150+ $ msgType = 'Creating ' ;
150151 }
151- $ body ['body ' ][ ' mappings ' ] = $ mappings ;
152- $ msg = sprintf ($ msg , ' Creating ' , $ indexName );
152+ $ body ['body ' ] = $ mappings ;
153+ $ msg = sprintf ($ msg , $ msgType , $ indexName );
153154 DB ::alteration_message ($ msg );
154155 $ this ->getLogger ()->info ($ msg );
155156
156- return $ client ->indices ()->create ($ body );
157+ return $ client ->indices ()->$ method ($ body );
157158 }
158159
159160 /**
@@ -223,7 +224,7 @@ protected function getMethod(ElasticIndex $index): string
223224 $ check = $ index ->indexExists ();
224225
225226 if ($ check ) {
226- return 'update ' ;
227+ return 'putMapping ' ;
227228 }
228229
229230 return 'create ' ;
0 commit comments