javascript - Elasticsearch 5.3 - 找不到geo_point字段

标签 javascript elasticsearch kibana elasticsearch-5 kibana-5

我指的是这个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/

相关文章:

ruby-on-rails - Ruby on Rails - ElasticSearch 结果窗口太大

elasticsearch - 如何安全地将Elasticsearch索引移动到Linux中的另一个装载?

elasticsearch - 弹性:我想写一个查询(在特定月份的任何时候,每小时经历的峰值量)

javascript - 如何在多行文本的文本区域中添加换行符

javascript - 从团队应用程序中的页面重定向阻止我的页面

javascript - 将 JSON 对象发送到 Web 服务时 $.ajax 函数失败

elasticsearch - Elasticsearch顶级聚合/搜索主体元数据

java - 如何使用java列出elasticsearch的所有索引名称?

elasticsearch - 在ElasticSearch中建立索引以进行审核

javascript - 如何使用ajax传递多个值?