gpt4 book ai didi

elasticsearch - geo_distance仅对查询的特定条件进行过滤?

转载 作者:行者123 更新时间:2023-12-03 01:40:52 24 4
gpt4 key购买 nike

所以这是我的问题,我有一个查询生成器,它根据发送到API的参数来生成查询,这是它生成的查询的一个示例

{
"from": 0,
"size": 50,
"query": {
"filtered": {
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "nrc",
"fields": [
"name",
"sector.group.name",
"description",
"professionDescription"
]
}
},
{
"term": {
"alternate": "true"
}
},
{
"term": {
"flagInitial": "true"
}
},
{
"term": {
"flagDistance": "true"
}
}
],
"must": [],
"minimum_should_match": 2
}
},
"filter": {
"geo_distance": {
"distance": "80km",
"institute.location": {
"lat": "48.866667",
"lon": "2.333333"
}
}
}
}
},
"track_scores": true,
"sort": {
"institute.premium": {
"order": "desc"
},
"_geo_distance": {
"location": {
"lat": "48.866667",
"lon": "2.333333"
}
}
}

}

如您所见,我们具有多重匹配项和不同的标志,并且整个查询使用指定坐标周围的geo_distance进行过滤。在这种情况下,问题在于我们不希望将此过滤器应用于“flagDistance”一词,因为如果flagDistance = true,我们希望所有具有flagDistance = true的机构都在哪里,但我们仍然希望这样做过滤器以应用于查询的其他标志/ multi_match。

任何想法如何做到这一点?

我希望可以在第一个查询(过滤的查询)之后添加另一个查询,但是它返回错误
"query": {
"filtered": {
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "nrc",
"fields": [
"name",
"sector.group.name",
"description",
"professionDescription"
]
}
},
{
"term": {
"alternate": "true"
}
},
{
"term": {
"flagInitial": "true"
}
}
],
"must": [],
"minimum_should_match": 2
}
},
"filter": {
"geo_distance": {
"distance": "80km",
"institute.location": {
"lat": "48.866667",
"lon": "2.333333"
}
}
}
},
"bool": {
"should": [
{
"term": {
"flagDistance": "true"
}
}
]
}
}

最佳答案

所以这就是我解决问题的方式,我的过滤器中的should子句允许我过滤,如果它是flagDistance = true文档,或者距给定坐标80公里

{
"from": 0,
"size": 50,
"query": {
"filtered": {
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "muc",
"fields": [
"name",
"sector.group.name",
"description",
"professionDescription"
]
}
},
{
"term": {
"alternate": "true"
}
},
{
"term": {
"flagDistance": "true"
}
}
],
"must": [],
"minimum_should_match": 2
}
},
"filter": {
"bool": {
"should": {
"geo_distance": {
"distance": "80km",
"institute.location": {
"lat": "48.866667",
"lon": "2.333333"
}
},
"term": {
"flagDistance": "true"
}
}
}
}
}
},
"track_scores": true,
"sort": {
"institute.premium": {
"order": "desc"
},
"_geo_distance": {
"location": {
"lat": "48.866667",
"lon": "2.333333"
}
}
}
}

关于elasticsearch - geo_distance仅对查询的特定条件进行过滤?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47747837/

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