gpt4 book ai didi

php - ElasticSearch-范围查询不起作用

转载 作者:行者123 更新时间:2023-12-03 01:56:44 25 4
gpt4 key购买 nike

我是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应该是一个子句数组,而在上面,它是一个带有键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,
]
]);

关于php - ElasticSearch-范围查询不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35970467/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com