gpt4 book ai didi

elasticsearch - ElasticSearch:当hits = 0时,在响应主体内返回查询

转载 作者:行者123 更新时间:2023-12-02 23:27:39 25 4
gpt4 key购买 nike

请注意,以下示例是现实生活用例的非常精简的版本,它是为了使问题易于阅读并提出要点。

我具有以下文档结构:

{
"date" : 1400500,
"idc" : 1001,
"name": "somebody",
}

我正在根据不同的值(“idc”和“date”范围)执行_msearch查询(一次多次搜索)
当ES在给定日期范围内找不到任何文档时,它将返回:
"hits":{  
"total":0,
"max_score":null,
"hits":[
]
}

但是,由于有N个结果,因此我无法确定该结果是针对哪个“idc”以及哪个“日期”范围。
当给定查询没有结果时,我希望响应具有“搜索”日期范围和“idc”。例如,如果我正在搜索IDC = 1001且日期在1400100和1400200之间的文档,但是没有找到结果,则响应应在响应正文中包含查询词,如下所示:
"hits":{  
"total":0,
"max_score":null,
"query": {
"date": {
"gt": 1400100,
"lte": 1400200,
}
"idc": 1001,
}
}

这样,我可以分辨出什么日期范围和“idc”组合没有结果。
请注意,上面的示例是真实生活用例的非常精简的版本,它是为了使问题易于阅读并提出要点。

最佳答案

这是从文档

multi search API(_msearch) response returns a responses array, which includes the search response and status code for each search request matching its order in the original multi search request.



由于您知道发送请求的顺序,因此可以找出哪个请求失败。

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html

关于elasticsearch - ElasticSearch:当hits = 0时,在响应主体内返回查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40952595/

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