gpt4 book ai didi

elasticsearch - 如何在Elasticsearch 7.x中将geo_distance过滤器用作OR条件?

转载 作者:行者123 更新时间:2023-12-03 01:19:21 28 4
gpt4 key购买 nike

我正在使用Elasticsearch 7.6,并尝试运行一个查询,该查询运行geo_distance查询以在这种情况下在25英里范围内的确切城市中查找匹配的文档。

用外行的话来说,将是“搜索“加利福尼亚州圣罗莎市”或其周围25英里内的所有工作。如果在加利福尼亚圣罗莎市内25英里内有工作,则应在搜索中返回这些文档除“job_location”字段专门为“Santa Rosa,CA”的所有作业外,还会产生结果

这是我的查询,尽管在我指定的经度和纬度(加利福尼亚州圣罗莎)的25英里范围内有匹配的文档,但仍返回0个结果。

我必须语法错误。

{
"query": {
"bool": {
"filter": {
"geo_distance": {
"distance": "25 miles",
"geo_location": "38.440429,-122.7140548"
}
},
"must": [
{
"match": {
"active": true
}
},
{
"bool": {
"should": [
{
"term": {
"job_location": "Santa Rosa, CA"
}
}
]
}
}
]
}
}
}

最佳答案

您的查询构建不正确。尝试这样,它应该会按预期工作。 OR条件应全部在bool/should中:

{
"query": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"term": {
"job_location": "Santa Rosa, CA"
}
},
{
"geo_distance": {
"distance": "25m",
"geo_location": "38.440429,-122.7140548"
}
}
],
"filter": [
{
"match": {
"active": true
}
}
]
}
}
}

关于elasticsearch - 如何在Elasticsearch 7.x中将geo_distance过滤器用作OR条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61000680/

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