0

我想将查询的一半放入变量中$query并将其放入$paramsElasticSearch 中。

这是我的$query

if (Input::has('_id')) {
          $_id = $this->input['_id'];
          $path = 'data';
          $field = 'data.city';

          // Querying city
          if (Input::has('city')) {
              $city = $this->input['city'];
              $query = array('query'=> [
                      'bool' => [
                        'must' => [
                          [
                            'match' => [
                              '_id' => $_id
                            ]
                          ],
                          [
                            'nested' => [
                              'path' => $path,
                              'query' => [
                                'bool' => [
                                  'must' => [
                                    [
                                      'match' => [
                                        $field => $city
                                      ]
                                    ]
                                  ]
                                ]
                              ]
                            ]
                          ]
                        ]
                      ]
                    ]);
          }

我想把这个变量放在$params 这样的地方:

$params = [
            'index' => 'channels',
            'type' => 'users',
            'body' => [
                'from' => $defaultPerPage * ($page - 1),
                'size' => $defaultPerPage,
                $query
            ]
      ];

我尝试print_r($params)并得到了正确的结果。但是我在尝试查询时总是收到错误通知。任何人都知道该怎么做?

谢谢

错误 :

{"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[6fZ0ud3kSTSYsMI-o-mg4w][channels][0]: SearchParseException[[channels][0]: from[0],size[10]: Parse Failure [Failed to parse source [{\"from\":0,\"size\":10,\"0\":{\"query\":{\"bool\":{\"must\":[{\"match\":{\"_id\":\"9121200asda121\"}},{\"nested\":{\"path\":\"data\",\"query\":{\"bool\":{\"must\":[{\"match\":{\"data.city\":\"california\"}}]}}}}]}}}}]]]; nested: SearchParseException[[channels][0]: from[0],size[10]: Parse Failure [No parser for element [0]]]; }{[W5E62t0EQ16lckCUnf8atw][channels][1]: RemoteTransportException[[Bima][inet[/10.200.7.69:9300]][indices:data/read/search[phase/query]]]; nested: SearchParseException[[channels][1]: from[0],size[10]: Parse Failure [Failed to parse source [{\"from\":0,\"size\":10,\"0\":{\"query\":{\"bool\":{\"must\":[{\"match\":{\"_id\":\"9121200asda121\"}},{\"nested\":{\"path\":\"data\",\"query\":{\"bool\":{\"must\":[{\"match\":{\"data.city\":\"california\"}}]}}}}]}}}}]]]; nested: SearchParseException[[channels][1]: from[0],size[10]: Parse Failure [No parser for element [0]]]; }{[6fZ0ud3kSTSYsMI-o-mg4w][channels][2]: SearchParseException[[channels][2]: from[0],size[10]: Parse Failure [Failed to parse source [{\"from\":0,\"size\":10,\"0\":{\"query\":{\"bool\":{\"must\":[{\"match\":{\"_id\":\"9121200asda121\"}},{\"nested\":{\"path\":\"data\",\"query\":{\"bool\":{\"must\":[{\"match\":{\"data.city\":\"california\"}}]}}}}]}}}}]]]; nested: SearchParseException[[channels][2]: from[0],size[10]: Parse Failure [No parser for element [0]]]; }]","status":400}
4

0 回答 0