@@ -129,14 +129,14 @@ public function createNestedAggs($columns, $sort)
129129 if (!isset ($ terms ['terms ' ]['order ' ])) {
130130 $ terms ['terms ' ]['order ' ] = [];
131131 }
132- if ($ sort ['_count ' ] == 1 ) {
132+ if ($ sort ['_count ' ] == ' asc ' ) {
133133 $ terms ['terms ' ]['order ' ][] = ['_count ' => 'asc ' ];
134134 } else {
135135 $ terms ['terms ' ]['order ' ][] = ['_count ' => 'desc ' ];
136136 }
137137 }
138138 if (isset ($ sort [$ columns [0 ]])) {
139- if ($ sort [$ columns [0 ]] == 1 ) {
139+ if ($ sort [$ columns [0 ]] == ' asc ' ) {
140140 $ terms ['terms ' ]['order ' ][] = ['_key ' => 'asc ' ];
141141 } else {
142142 $ terms ['terms ' ]['order ' ][] = ['_key ' => 'desc ' ];
@@ -205,15 +205,15 @@ private function _buildQuery($wheres): array
205205 }
206206
207207
208- public function _convertWheresToDSL ($ wheres ): array
208+ public function _convertWheresToDSL ($ wheres, $ parentField = false ): array
209209 {
210210 $ dsl = ['bool ' => []];
211211 foreach ($ wheres as $ logicalOperator => $ conditions ) {
212212 switch ($ logicalOperator ) {
213213 case 'and ' :
214214 $ dsl ['bool ' ]['must ' ] = [];
215215 foreach ($ conditions as $ condition ) {
216- $ parsedCondition = $ this ->_parseCondition ($ condition );
216+ $ parsedCondition = $ this ->_parseCondition ($ condition, $ parentField );
217217 if (!empty ($ parsedCondition )) {
218218 $ dsl ['bool ' ]['must ' ][] = $ parsedCondition ;
219219 }
@@ -225,7 +225,7 @@ public function _convertWheresToDSL($wheres): array
225225 $ boolClause = ['bool ' => ['must ' => []]];
226226 foreach ($ conditionGroup as $ subConditions ) {
227227 foreach ($ subConditions as $ subCondition ) {
228- $ parsedCondition = $ this ->_parseCondition ($ subCondition );
228+ $ parsedCondition = $ this ->_parseCondition ($ subCondition, $ parentField );
229229 if (!empty ($ parsedCondition )) {
230230 $ boolClause ['bool ' ]['must ' ][] = $ parsedCondition ;
231231 }
@@ -237,17 +237,22 @@ public function _convertWheresToDSL($wheres): array
237237 }
238238 break ;
239239 default :
240- return $ this ->_parseCondition ($ wheres );
240+ return $ this ->_parseCondition ($ wheres, $ parentField );
241241 }
242242 }
243243
244244 return $ dsl ;
245245 }
246246
247- private function _parseCondition ($ condition ): array
247+ private function _parseCondition ($ condition, $ parentField = null ): array
248248 {
249- // dd($condition);
250249 $ field = key ($ condition );
250+ if ($ parentField ) {
251+ if (!str_starts_with ($ field , $ parentField .'. ' )) {
252+ $ field = $ parentField .'. ' .$ field ;
253+ }
254+ }
255+
251256 $ value = current ($ condition );
252257
253258
@@ -345,7 +350,7 @@ private function _parseCondition($condition): array
345350 $ queryPart = [
346351 'nested ' => [
347352 'path ' => $ field ,
348- 'query ' => $ this ->_convertWheresToDSL ($ operand ['wheres ' ]),
353+ 'query ' => $ this ->_convertWheresToDSL ($ operand ['wheres ' ], $ field ),
349354 'score_mode ' => $ operand ['score_mode ' ],
350355 ],
351356 ];
@@ -390,8 +395,8 @@ private function _buildOptions($options): array
390395 if (!isset ($ return ['body ' ]['sort ' ])) {
391396 $ return ['body ' ]['sort ' ] = [];
392397 }
393- foreach ($ value as $ field => $ direction ) {
394- $ return ['body ' ]['sort ' ][] = $ this -> _parseSortOrder ($ field , $ direction );
398+ foreach ($ value as $ field => $ sortPayload ) {
399+ $ return ['body ' ]['sort ' ][] = ParameterBuilder:: fieldSort ($ field , $ sortPayload );
395400 }
396401 break ;
397402 case 'skip ' :
@@ -405,8 +410,10 @@ private function _buildOptions($options): array
405410 $ this ->_parseFilter ($ filterType , $ filerValues );
406411 }
407412 break ;
413+
408414 case 'multiple ' :
409415 case 'searchOptions ' :
416+
410417 //Pass through
411418 break ;
412419 default :
@@ -440,15 +447,6 @@ public function _parseFilter($filterType, $filterPayload): void
440447 }
441448 }
442449
443- private function _parseSortOrder ($ field , $ direction ): array
444- {
445- $ dir = 'desc ' ;
446- if ($ direction == 1 ) {
447- $ dir = 'asc ' ;
448- }
449-
450- return ParameterBuilder::fieldSort ($ field , $ dir );
451- }
452450
453451 public function _parseFilterParameter ($ params , $ filer )
454452 {
0 commit comments