@@ -342,48 +342,6 @@ protected function getSkip()
342
342
return $ this ->skip ;
343
343
}
344
344
345
-
346
- /**
347
- * Generate the query body
348
- * @return array
349
- */
350
- protected function getBody ()
351
- {
352
-
353
- $ body = [];
354
-
355
- if (count ($ this ->_source )) {
356
- $ body ["_source " ] = $ this ->_source ;
357
- }
358
-
359
- $ bool = [];
360
-
361
- if (count ($ this ->must )) {
362
- $ bool ["must " ] = $ this ->must ;
363
- }
364
-
365
- if (count ($ this ->must_not )) {
366
- $ bool ["must_not " ] = $ this ->must_not ;
367
- }
368
-
369
- if (count ($ this ->filter )) {
370
- $ bool ["filter " ] = $ this ->filter ;
371
- }
372
-
373
- if (count ($ bool )) {
374
- $ body ["query " ]["bool " ] = $ bool ;
375
- }
376
-
377
- if (count ($ this ->sort )) {
378
- $ body ["sort " ] = $ this ->sort ;
379
- }
380
-
381
- $ this ->body = $ body ;
382
-
383
- return $ body ;
384
- }
385
-
386
-
387
345
/**
388
346
* Set the sorting field
389
347
* @param $field
@@ -734,6 +692,63 @@ public function search($q = NULL, $boost = 1)
734
692
735
693
}
736
694
695
+ /**
696
+ * Generate the query body
697
+ * @return array
698
+ */
699
+ protected function getBody ()
700
+ {
701
+
702
+ $ body = $ this ->body ;
703
+
704
+ if (count ($ this ->_source )) {
705
+
706
+ $ _source = array_key_exists ("_source " , $ body ) ? $ body ["_source " ] : [];
707
+
708
+ $ body ["_source " ] = array_unique (array_merge ($ _source , $ this ->_source ));
709
+ }
710
+
711
+ if (count ($ this ->must )) {
712
+ $ body ["query " ]["bool " ]["must " ] = $ this ->must ;
713
+ }
714
+
715
+ if (count ($ this ->must_not )) {
716
+ $ body ["query " ]["bool " ]["must_not " ] = $ this ->must_not ;
717
+ }
718
+
719
+ if (count ($ this ->filter )) {
720
+ $ body ["query " ]["bool " ]["filter " ] = $ this ->filter ;
721
+ }
722
+
723
+ if (count ($ this ->sort )) {
724
+
725
+ $ sortFields = array_key_exists ("sort " , $ body ) ? $ body ["sort " ] : [];
726
+
727
+ $ body ["sort " ] = array_unique (array_merge ($ sortFields , $ this ->sort ), SORT_REGULAR );
728
+
729
+ }
730
+
731
+ $ this ->body = $ body ;
732
+
733
+ return $ body ;
734
+ }
735
+
736
+
737
+ /**
738
+ * set the query body array
739
+ * @param array $body
740
+ * @return $this
741
+ */
742
+ function body ($ body = [])
743
+ {
744
+
745
+ $ this ->body = $ body ;
746
+
747
+ return $ this ;
748
+
749
+ }
750
+
751
+
737
752
/**
738
753
* Generate the query to be executed
739
754
* @return array
@@ -776,6 +791,7 @@ public function query()
776
791
777
792
}
778
793
794
+
779
795
/**
780
796
* Clear scroll query id
781
797
* @param string $scroll_id
0 commit comments