gpt4 book ai didi

elasticsearch - 弹性-多个过滤器查询语法

转载 作者:行者123 更新时间:2023-12-03 01:42:14 29 4
gpt4 key购买 nike

您好,我正在执行以下查询:

{
"_source": [
"source1",
"source2",
"source3",
"source4",
],
"query": {
"bool": {
"minimum_should_match": 1,
"must": {
"filter": [
{
"term": {
"_type": {
"value": "someval1"
}
}
},
{
"term": {
"_type": {
"value": "someval2"
}
}
}
],
"query_string": {
"analyze_wildcard": "true",
"query": "tesla*",
"rewrite": "scoring_boolean"
}
}
}
},
"size": 50,
"sort": [
"_score"
]
}

当前正在返回:
'"reason":"[bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]","line":1,"col":343},"status":400}'

任何想法如何在查询上使用多个过滤器?我可以在Elastic 2.4上做到这一点,但是由于OR现在已被弃用和过滤,因此我有点迷失了。

谢谢!

最佳答案

查询的语法错误。不应将filter包装到must语句中。它应该与must处于同一级别。另外bool查询must语句应该是一个数组,而不是对象。因此您的查询应如下所示

{
"_source":[
"source1",
"source2",
"source3",
"source4"
],
"query":{
"bool":{
"minimum_should_match":1,
"must":[
{
"query_string":{
"analyze_wildcard":"true",
"query":"tesla*",
"rewrite":"scoring_boolean"
}
}
],
"filter":{
"bool":{
"should":[
{
"term":{
"_type":{
"value":"someval1"
}
}
},
{
"term":{
"_type":{
"value":"someval2"
}
}
}
]
}
}
}
},
"size":50,
"sort":[
"_score"
]
}

我认为您的过滤器是 OR,这就是为什么我将其包装在 should中的原因

关于elasticsearch - 弹性-多个过滤器查询语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46673713/

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