gpt4 book ai didi

elasticsearch - ElasticSearch排除满足条件的结果

转载 作者:行者123 更新时间:2023-12-02 23:15:38 24 4
gpt4 key购买 nike

我想从满足条件的geo_distance筛选中排除一些结果。

例如,我按地理距离过滤结果,但我想包括状态异常且满足match_phrase查询的所有结果(即使它不在geo_distance之外)

        GET /drive/_search
{
"query": {
"bool": {
"should": [
{
"match_phrase": {
"keywords": "wheels"
}
},
{
"match_phrase": {
"name": "car sale"
}
}
],
"filter": [
{
"term": {
"status": "normal"
}
},
{
"geo_distance": {
"distance": "0.09km",
"address.coordinate": {
"lat": -33.703082,
"lon": 18.981069
}
}
}
]
}
}
}

我一直在阅读文档并进行谷歌搜索,但是我认为我可能走错了方向。

如果您能为我指明正确的方向,或者向我解释这样做会是一个更好的解决方案,那么我将不胜感激。

最佳答案

doc:

should

The clause (query) should appear in the matching document. If the bool query is in a query context and has a must or filter clause then a document will match the bool query even if none of the should queries match. In this case these clauses are only used to influence the score. If the bool query is in a filter context or has neither must or filter then at least one of the should queries must match a document for it to match the bool query. This behavior may be explicitly controlled by setting the minimum_should_match parameter.



因此,在您的情况下,地理位置条件在“ 应该为”中,因为它可以是可选的,其余条件在“ 过滤器”中,这是必选的:状态和match_phrase

试试这个:
{
"query": {
"bool": {
"filter": [
{
"term": {
"status": "normal"
}
},
{
"match_phrase": {
"name": "car sale"
}
},

{
"match_phrase": {
"keywords": "wheels"
}
}
],
"should": [
{
"geo_distance": {
"distance": "0.09km",
"address.coordinate": {
"lat": -33.703082,
"lon": 18.981069
}
}
}
]
}
}
}

关于elasticsearch - ElasticSearch排除满足条件的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55594704/

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