2016-03-13 66 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