elasticsearch - 重新索引失败,数组映射到geo_point

标签 elasticsearch

我试图将一个字段的映射从text类型更改为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]"
      }
    }
  },

最佳答案

问题是在您的source_index中,即latitude.lat_long字段不符合 geo_point 数据类型支持的有效的四种不同表示形式。

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

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

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

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

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

步骤1:建立Ingest Pipeline

执行以下查询以创建管道,该管道会将input formatlatitude.lat_long转换为如上所述的所需格式
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

测试,验证,让我知道如何进行。

关于elasticsearch - 重新索引失败,数组映射到geo_point,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55228591/

相关文章:

elasticsearch - elastic v7.x 中使用的 utf8json 是否支持用户定义的自定义格式化程序?

elasticsearch - Elasticsearch 在 query_string 精确搜索中使用通配符

elasticsearch - Logstash输出指数每年轮换

ruby-on-rails - 重新轮胎 Elasticsearch 多表/索引搜索

Elasticsearch [1.4.4] :Range search on numeric index with non numeric input

elasticsearch - Elastic Search查询不适用于curl

elasticsearch - 字词汇总-汇总所有文档中的每个单词

django - Django Celery 任务中的 Elasticsearch 索引

elasticsearch - Elasticsearch匹配查询与带有撇号的文档不匹配

java - Elasticsearch 优先考虑从匹配开始