【问题标题】:Reindex fails with array mapped to geo_point重新索引失败,数组映射到 geo_point
【发布时间】:2019-03-19 07:06:16
【问题描述】:

在将一个字段的映射从文本类型更改为geo_point 类型后,我正在尝试重新索引。

源索引中的现有数据如下所示:

  "location" : {
    "lat_long" : [
      "49.266498",
      "-122.998938"
    ],

如何在_reindex api 调用中遇到以下故障:

"cause": {
    "type": "mapper_parsing_exception",
    "reason": "failed to parse field [location.lat_long] of type [geo_point]",
    "caused_by": {
      "type": "parse_exception",
      "reason": "unsupported symbol [.] in geohash [49.228065]",
      "caused_by": {
        "type": "illegal_argument_exception",
        "reason": "unsupported symbol [.] in geohash [49.228065]"
      }
    }
  },

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    问题在于您的source_indexlatitude.lat_long 字段不符合geo_point 数据类型支持的有效四种不同表示中的任何一种。

    因此,当您尝试重新索引时转换失败。

    唯一适用的 string 表示形式为以下格式 "lat, lon",但您拥有的是 [ "lat", "lon" ],它只是字符串数组。

    如果表示为以下格式,则重新索引将成功执行。

    "location" : {
        "lat_long" : "49.266498, -122.998938"
        ]
     }
    

    作为一种解决方案,您可以执行以下步骤:

    第一步:创建Ingest Pipeline

    执行以下查询以创建将latitude.lat_longinput format 转换为我上面提到的所需格式的管道

    PUT _ingest/pipeline/my-pipeline-geo
    {
      "description" : "geo-point pipeline",
      "processors" : [
        {
            "script": {
              "lang": "painless",
              "source": "ctx.temp = \"\"; for (def item : ctx.location.lat_long) { if(ctx.temp==\"\") { ctx.temp += item } else { ctx.temp = ctx.temp + ', ' + item} }"
            }
          },
          {
            "remove": {
              "field": "location"
            }
          },
          {
            "set": {
              "field": "location.lat_long",
              "value": "{{temp}}"
            }
          },
          {
            "remove": {
              "field": "temp"
            }
          }
      ]
    }
    

    第 2 步:执行以下重新索引查询

    POST _reindex
    {
      "source": {
        "index": "source_index"
      },
      "dest": {
        "index": "dest_index",
        "pipeline": "my-pipeline-geo"
      }
    }
    

    请注意我在重新索引步骤中如何使用在步骤 1 中创建的管道。 输出将采用我上面提到的格式。花点时间阅读一下 elasticsearch 中内置的Ingestion API

    测试、验证并告诉我进展如何。

    【讨论】:

    • 嘿@WindDude,上述帮助。您还在寻找其他东西吗?
    猜你喜欢
    • 2020-07-30
    • 2017-10-08
    • 1970-01-01
    • 2016-07-03
    • 1970-01-01
    • 2015-05-16
    • 1970-01-01
    • 1970-01-01
    • 2012-03-06
    相关资源
    最近更新 更多