Elasticsearch 地理空间查询未返回任何命中
Elasticsearch geospatial queries returning no hits
我正在使用 Kibana 查看 Elasticsearch 中的地理空间数据集以了解当前正在开发的功能。有一个包含字段 "loc.coordinates" 的位置索引,它是一个 geo_point,并且具有这样的数据:
loc.coordinates 25.906958000000003, 51.776407000000006
然而,当我 运行 以下查询时,我没有得到任何结果:
查询
GET /positions/_search
{
"query": {
"bool" : {
"must" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "2000km",
"loc.coordinates" : {
"lat" : 25,
"lon" : 51
}
}
}
}
}
}
回应
{
"took": 12,
"timed_out": false,
"_shards": {
"total": 6,
"successful": 6,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
我试图理解这是为什么,因为索引中有超过 250,000 个数据点,而且无论搜索区域有多大,我都没有找到任何结果。当我查看位置索引映射时,我看到以下内容:
"loc": {
"type": "nested",
"properties": {
"coordinates": {
"type": "geo_point"
},
"type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
我是 Elasticsearch 的新手,一直在阅读文档,但到目前为止我不明白为什么我的地理查询没有按预期工作。我做错了什么?
您的 loc
字段属于 nested
类型,因此您需要使用 nested
查询相应地查询该字段:
GET /positions/_search
{
"query": {
"bool" : {
"filter" : {
"nested": {
"path": "loc",
"query": {
"geo_distance" : {
"distance" : "2000km",
"loc.coordinates" : {
"lat" : 25,
"lon" : 51
}
}
}
}
}
}
}
}
我正在使用 Kibana 查看 Elasticsearch 中的地理空间数据集以了解当前正在开发的功能。有一个包含字段 "loc.coordinates" 的位置索引,它是一个 geo_point,并且具有这样的数据:
loc.coordinates 25.906958000000003, 51.776407000000006
然而,当我 运行 以下查询时,我没有得到任何结果:
查询
GET /positions/_search
{
"query": {
"bool" : {
"must" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "2000km",
"loc.coordinates" : {
"lat" : 25,
"lon" : 51
}
}
}
}
}
}
回应
{
"took": 12,
"timed_out": false,
"_shards": {
"total": 6,
"successful": 6,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
我试图理解这是为什么,因为索引中有超过 250,000 个数据点,而且无论搜索区域有多大,我都没有找到任何结果。当我查看位置索引映射时,我看到以下内容:
"loc": {
"type": "nested",
"properties": {
"coordinates": {
"type": "geo_point"
},
"type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
我是 Elasticsearch 的新手,一直在阅读文档,但到目前为止我不明白为什么我的地理查询没有按预期工作。我做错了什么?
您的 loc
字段属于 nested
类型,因此您需要使用 nested
查询相应地查询该字段:
GET /positions/_search
{
"query": {
"bool" : {
"filter" : {
"nested": {
"path": "loc",
"query": {
"geo_distance" : {
"distance" : "2000km",
"loc.coordinates" : {
"lat" : 25,
"lon" : 51
}
}
}
}
}
}
}
}