【问题标题】:Elasticsearch illegal mapping of a location arrayElasticsearch非法映射位置数组
【发布时间】:2020-03-16 22:55:28
【问题描述】:

我想在我的数据集上使用 elasticsearch 执行地理位置查询,如下所示:

{"index": {"_index": "city","_type":"city_info", "_id":0} }
{"fields": { "city" : "AGAWAM", 
             "loc" : [ -72.622739, 42.070206 ], 
             "pop" : 15338, "state" : "MA"},
             "id" : "01001" ,
             "type" : "add"}
...

我能够毫无问题地执行大量查询或聚合,但是当涉及到使用地理距离过滤器或任何在地理坐标上工作的查询时,它就不起作用了。这是我的映射测试:

PUT /city/_mappings
{
  "properties": {
    "fields.loc": {
      "type": "geo_point"
    }
  }
}

我收到此错误。

{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "mapper [fields.loc] of different type, current_type [float], merged_type [geo_point]"
      }
    ],
    "type" : "illegal_argument_exception",
    "reason" : "mapper [fields.loc] of different type, current_type [float], merged_type [geo_point]"
  },
  "status" : 400
}

所以看起来我的“fields.loc”是一个浮点数,而在 JSON 中它是一个包含浮点值的数组。我试图查看“loc”的实际类型是什么,它确实是一个浮点数,我不明白为什么:

GET /city/_mapping
{
  "city" : {
    "mappings" : {
      "properties" : {
        "fields" : {
          "properties" : {
            "city" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "loc" : {
              "type" : "float"
...

所以我不明白,或者更确切地说,我不知道如何将“loc”从浮点数修改为 geo_point。 由于我是 elasticsearch 的初学者,我只使用 elasticsearch 和 kibana 进行 cURL。

【问题讨论】:

    标签: elasticsearch geolocation mapping


    【解决方案1】:

    一旦您将数据类型隐式设置为浮点数(通过批量同步,您可能会这样做),将很难将浮点数转换为 geo_points。 我建议删除索引,使用 geo_point 数据类型设置正确的映射并重新同步所有内容。

    如果您想深入了解,请查看_reindex api。这是quick tut。当您的系统在现在可以选择删除的生产环境中运行时,您可能会遇到这种情况。

    仅供参考,不推荐使用custom _doc 类型。

    【讨论】:

    • 谢谢!我已经完成了您建议我做的第一件事:删除索引,使用正确的映射设置新索引,其中“loc”类型为“geo_point”)并再次批量同步。现在我的 geo_distance 查询正在运行
    • 不错。乐于助人!
    猜你喜欢
    • 2021-08-07
    • 1970-01-01
    • 1970-01-01
    • 2017-01-19
    • 2012-07-11
    • 1970-01-01
    • 2014-11-27
    • 1970-01-01
    • 2016-07-05
    相关资源
    最近更新 更多