File tree Expand file tree Collapse file tree 3 files changed +73
-0
lines changed
Expand file tree Collapse file tree 3 files changed +73
-0
lines changed Original file line number Diff line number Diff line change @@ -436,6 +436,21 @@ $searchParameters->scriptFields([
436436 ],
437437]);
438438
439+ // runtime mappings
440+ $searchParameters->runtimeMappings([
441+ 'day_of_week' => [
442+ 'type' => 'long',
443+ 'script' => [
444+ 'lang' => 'painless',
445+ 'source' => 'doc[params.field] * params.multiplier',
446+ 'params' => [
447+ 'field' => 'my_field',
448+ 'multiplier' => 2,
449+ ],
450+ ],
451+ ],
452+ ]);
453+
439454// boost indices
440455$searchParameters->indicesBoost([
441456 ['my-alias' => 1.4],
Original file line number Diff line number Diff line change @@ -116,6 +116,18 @@ public function scriptFields(array $scriptFields): self
116116 return $ this ;
117117 }
118118
119+ public function runtimeMappings (array $ runtimeFields ): self
120+ {
121+ $ this ->params ['body ' ]['runtime_mappings ' ] = $ runtimeFields ;
122+ return $ this ;
123+ }
124+
125+ public function fields (array $ fields ): self
126+ {
127+ $ this ->params ['body ' ]['fields ' ] = $ fields ;
128+ return $ this ;
129+ }
130+
119131 public function searchType (string $ searchType ): self
120132 {
121133 $ this ->params ['search_type ' ] = $ searchType ;
Original file line number Diff line number Diff line change @@ -314,6 +314,41 @@ public function test_array_casting_with_script_fields(): void
314314 ], $ searchParameters ->toArray ());
315315 }
316316
317+ public function test_array_casting_with_runtime_mappings (): void
318+ {
319+ $ searchParameters = (new SearchParameters ())->runtimeMappings ([
320+ 'day_of_week ' => [
321+ 'type ' => 'long ' ,
322+ 'script ' => [
323+ 'lang ' => 'painless ' ,
324+ 'source ' => 'doc[params.field] * params.multiplier ' ,
325+ 'params ' => [
326+ 'field ' => 'my_field ' ,
327+ 'multiplier ' => 2 ,
328+ ],
329+ ],
330+ ],
331+ ]);
332+
333+ $ this ->assertEquals ([
334+ 'body ' => [
335+ 'runtime_mappings ' => [
336+ 'day_of_week ' => [
337+ 'type ' => 'long ' ,
338+ 'script ' => [
339+ 'lang ' => 'painless ' ,
340+ 'source ' => 'doc[params.field] * params.multiplier ' ,
341+ 'params ' => [
342+ 'field ' => 'my_field ' ,
343+ 'multiplier ' => 2 ,
344+ ],
345+ ],
346+ ],
347+ ],
348+ ],
349+ ], $ searchParameters ->toArray ());
350+ }
351+
317352 public function test_array_casting_with_min_score (): void
318353 {
319354 $ searchParameters = (new SearchParameters ())->minScore (0.5 );
@@ -325,6 +360,17 @@ public function test_array_casting_with_min_score(): void
325360 ], $ searchParameters ->toArray ());
326361 }
327362
363+ public function test_array_casting_with_fields (): void
364+ {
365+ $ searchParameters = (new SearchParameters ())->fields (['my_field ' ]);
366+
367+ $ this ->assertEquals ([
368+ 'body ' => [
369+ 'fields ' => ['my_field ' ],
370+ ],
371+ ], $ searchParameters ->toArray ());
372+ }
373+
328374 public function test_array_casting_with_search_type (): void
329375 {
330376 $ searchParameters = (new SearchParameters ())->searchType ('query_then_fetch ' );
You can’t perform that action at this time.
0 commit comments