【问题标题】:Use geo_point data type on field in _reindex api在 _reindex api 中的字段上使用 geo_point 数据类型
【发布时间】:2019-03-28 13:53:35
【问题描述】:

我的索引包含两个字段:存储为浮点数的经度和纬度。我想创建新索引并从第一个索引复制数据,但映射不同。我使用带有弹性处理器的 reindex api,它可以重命名字段并赋予它们不同的数据类型。当我尝试创建类型为“geo_point”的字段时,它失败了。

"type": "parse_exception",
       "reason": "[type] type [geo_point] not supported, cannot convert field.",

但是当我创建新索引时,我能够创建具有“geo_point”类型的字段。 我尝试了不同的解决方法,但文档说使用地理查询只能使用“geo_point”类型。 有什么解决办法吗?

{
  "description": "test pipe",
  "processors": [
    {
      "convert": {
        "field": "location", 
        "type": "geo_point"
      }
    }
  ]
}

添加了管道定义。

【问题讨论】:

  • 请显示您的摄取管道定义
  • 抱歉这么晚了:) 添加了管道定义。
  • 能否请您出示您的地图和示例文档?
  • 基本上问题是这个管道无效,kibana显示错误,意思是任何字段都不能转换为geo_point类型。当我想创建这个管道时发生错误。
  • 你真的有一个叫做location的字段吗?您能说明一下管道创建错误是什么吗?

标签: elasticsearch kibana


【解决方案1】:

好的,假设您当前的索引映射如下所示:

PUT oldindex
{
  "mappings": {
    "doc": {
      "properties": {
        "latitude": {
          "type": "float"
        },
        "longitude": {
          "type": "float"
        }
      }
    }
  }
}

您需要使用正确的映射创建一个新索引,如下所示

PUT newindex
{
  "mappings": {
    "doc": {
      "properties": {
        "location": {
          "type": "geo_point"
        }
      }
    }
  }
}

然后,您可以简单地利用 reindex API 将旧索引复制到新索引中,并使用一些额外的脚本来创建位置字段:

POST _reindex
{
  "source": {
    "index": "oldindex",
  },
  "dest": {
    "index": "newindex"
  },
  "script": {
    "source": "ctx._source.location = ['lat': ctx._source.latitude, 'lon': ctx._source.longitude]; ctx._source.remove('latitude'); ctx._source.remove('longitude'); "
  }
}

您可以在新的闪亮索引中使用位置字段!

【讨论】:

  • 感谢您的评论!问题是我无法对该字段执行地理查询,elastic 说它不是 geo_point 数据类型。
  • 这个运气好吗?
  • 哪个字段?,如果你创建一个新的索引,该字段是正确映射的
  • 谢谢你的帮助。这是正确的解决方案。很抱歉用这么大的间隔回答。!)
  • 太棒了,很高兴它有帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-03
  • 2012-10-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多