我指的是这个Geo Distance Query Elasticsearch 文档中给出的示例。
版本:5.3
根据教程,我执行此查询以在索引中插入数据
PUT /my_locations/location/1
{
"pin" : {
"location" : {
"lat" : 40.12,
"lon" : -71.34
}
}
}
然后我只是尝试应用地理距离查询,这也在文档中显示。
GET /my_locations/location/_search
{
"query": {
"bool" : {
"must" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "200km",
"pin.location" : {
"lat" : 40,
"lon" : -70
}
}
}
}
}
}
但它向我显示了这个错误。 “找不到 geo_point 字段 [pin.location]” 其他时候它向我展示了这个错误 “字段 [pin.location] 不是 geo_point 字段”。
我是否需要以不同的方式插入此记录,或者我在查询中缺少一些参数吗?
最佳答案
谢谢@Pierre Mallet
我查看了文档并得出结论,我首先需要使用 geo_point 数据类型创建索引。我无法在现有索引上应用数据类型。所以我的步骤是这样的
PUT gym
{
"mappings": {
"gyms": {
"properties": {
"location": {
"type": "geo_point"
}
}
}
}
}
插入包含位置的记录
PUT gym/gyms/1
{
"location" : [ -71.34, 41.12 ]
}
然后查找索引及其数据类型
GET /gym/gyms/_mapping/
您将看到位置字段具有 geo_point 数据类型。然后您就可以执行查询。
GET gym/gyms/_search
{
"query": {
"bool" : {
"must" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "150km",
"location" : [ -70.34, 40.12 ]
}
}
}
}
}
现在工作正常。
关于javascript - Elasticsearch 5.3 - 找不到geo_point字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49030060/