gpt4 book ai didi

elasticsearch - 无法解析搜索源。预期的字段名称,但获得了[START_OBJECT]

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

我想在Elasticsearch中表达这个SQL:

select * from ticket where user_id = 1 and (class_a = 1000010 or class_b = 16);

我使用组合过滤器,如下所示:

curl 'localhost:9200/ticket/_search?pretty' -d'
{
"query": {
"bool": {
"should": [
{"term": {"class_a": 1000010}},
{"term": {"class_b": 16}}
]
},
"filter": {
"term": {
"user_id": 1
}
}
}
}'


但是出现如下错误:

{
"error" : {
"root_cause" : [ {
"type" : "parse_exception",
"reason" : "failed to parse search source. expected field name but got [START_OBJECT]"
} ],
"type" : "search_phase_execution_exception",
"reason" : "all shards failed",
"phase" : "query_fetch",
"grouped" : true,
"failed_shards" : [ {
"shard" : 0,
"index" : "ticket",
"node" : "FO3-zhb1R1WCak381t88gQ",
"reason" : {
"type" : "parse_exception",
"reason" : "failed to parse search source. expected field name but got [START_OBJECT]"
}
} ]
},
"status" : 400
}


有人可以帮助我吗?提前致谢!

最佳答案

您快到了,您需要像这样重写查询(即,将filter移到bool子句中):

curl 'localhost:9200/ticket/_search?pretty' -d'{
"query": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"term": {
"class_a": 1000010
}
},
{
"term": {
"class_b": 16
}
}
],
"filter": {
"term": {
"user_id": 1
}
}
}
}
}'

关于elasticsearch - 无法解析搜索源。预期的字段名称,但获得了[START_OBJECT],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41117660/

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