ElasticSearch 按具有值或空值的地理位置进行过滤
ElasticSearch filter by geo location with value or null value
我正在将企业添加到 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 中。有些是地理定位的(经度、纬度坐标),有些只是在线业务(无坐标)。
我想做的是创建一个查询,在其中过滤具有给定地理位置和半径的企业。我想包括那些在线业务(没有地理坐标)。
你知道怎么做吗?
我试过这个:
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"
}
}
]
}
}
]
}
}
}