我是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,
]
]);
如果我删除范围查询,那么一切正常,我也检查了索引值和薪水(整数)。
谢谢
最佳答案
该查询不是有效的DSL。特别是,您在must
子句中缺少一堆括号。 bool查询中的must
应该是一个子句数组,而在上面,它是一个带有键match
和range
的对象。
范例:
$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,
]
]);