2016-03-13 109 views
0

我是ElasticSearch的新手,所以很抱歉,如果這不是問題。我試圖讓誰擁有的薪水低於某個值的用戶,但我得到這個錯誤:ElasticSearch - 範圍查詢不起作用

query_parsing_exception: No query registered for [salary] 

我的其他查詢工作正常,只有range query失敗,這是我的代碼:

$items = $this->client->search([ 
    'index' => 'offerprofiles', 
    'type' => 'profile', 
    'body' => [ 
     'query' => [ 
      'bool' => [ 
       "must" => [ 
        "match" => [ 
         "jobcategories.name" => [ 
          "query" => $query['category'] 
         ] 
        ], 
        "range" => [ 
         "salary" => [ 
          "lt" => 20 
         ] 
        ] 
       ], 
       "should" => [ 
        "match" => [ 
         "skills.name" => [ 
          "query" => $query['skills'] 
         ] 
        ] 
       ], 
       "minimum_should_match" => 1 
      ] 
     ], 
     'size' => 50, 
    ] 
]); 

如果我刪除範圍查詢,然後一切工作正常,我也檢查索引值和工資是有(整數)。 謝謝

回答

1

該查詢不是有效的DSL。在特定情況下,您在must子句中缺少一組括號。 bool查詢中的must應該是一個子句數組,而在上面它是一個帶有密鑰matchrange的對象。

例子:

$items = $this->client->search([ 
    'index' => 'offerprofiles', 
    'type' => 'profile', 
    'body' => [ 
     'query' => [ 
      'bool' => [ 
       "must" => [ 
       [ 
        "match" => [ 
         "jobcategories.name" => [ 
          "query" => $query['category'] 
         ] 
        ] 
       ], 
       [ 
        "range" => [ 
         "salary" => [ 
          "lt" => 20 
         ] 
        ] 
       ] 
       ], 
       "should" => [ 
        "match" => [ 
         "skills.name" => [ 
          "query" => $query['skills'] 
         ] 
        ] 
       ], 
       "minimum_should_match" => 1 
      ] 
     ], 
     'size' => 50, 
    ] 
]); 
+0

謝謝你一噸,現在一切都有道理 – Alen