gpt4 book ai didi

elasticsearch - ElasticSearch按地理位置值或空值过滤

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

我正在将业务添加到ElasticSearch中。有些位于地理位置(长期坐标,纬度坐标),有些仅是在线业务(无坐标)。

我想做的是创建一个查询,在其中过滤具有给定地理位置和半径的业务。我想包括那些在线业务(没有地理坐标)。

你有什么想法怎么做?

我已经试过了:

GET /organizations/_search
{
"query": {
"bool" : {
"must_not": {
"exists": {
"field": "geocoords"
}
},
"filter" : {
"geo_distance" : {
"distance" : "200km",
"geocoords" : {
"lon": -73.57,
"lat": 45.45
}
}
}
}
}
}

但是我没有结果:
{
"took" : 5,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 0,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
}
}

这是我的数据:
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "organizations",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"is_active" : true,
"name": "Compagny Inc.",
"geocoords" : {
"lon" : -73.5761003,
"lat" : 45.4560316
}
}
}
]
}
}

有任何提示或建议吗?谢谢。

最佳答案

当前查询是互斥的-您首先过滤掉有效的坐标,然后执行径向搜索...

相反,您可能需要逻辑或-半径范围内或根本没有坐标:

GET organizations/_search
{
"query": {
"bool": {
"should": [
{
"bool": {
"filter": {
"geo_distance": {
"distance": "200km",
"geocoords": {
"lon": -73.57,
"lat": 45.45
}
}
}
}
},
{
"bool": {
"must_not": [
{
"exists": {
"field": "geocoords"
}
}
]
}
}
]
}
}
}

关于elasticsearch - ElasticSearch按地理位置值或空值过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61740252/

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