elasticsearch - 在 _reindex api 中的字段上使用 geo_point 数据类型
问题描述
我的索引包含两个字段:存储为浮点数的经度和纬度。我想创建新索引并从第一个索引复制数据,但映射不同。我使用带有弹性处理器的 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"
}
}
]
}
添加了管道定义。
解决方案
好的,假设您当前的索引映射如下所示:
PUT oldindex
{
"mappings": {
"doc": {
"properties": {
"latitude": {
"type": "float"
},
"longitude": {
"type": "float"
}
}
}
}
}
您需要使用正确的映射创建一个新索引,如下所示
PUT newindex
{
"mappings": {
"doc": {
"properties": {
"location": {
"type": "geo_point"
}
}
}
}
}
然后,您可以简单地利用重新索引 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'); "
}
}
而且您可以在新的闪亮索引中使用位置字段!
推荐阅读
- sql-server - 类似于 DataTable 的 SQL 中如何循环遍历行和列
- imacros - iMacros:如何仅使第 1 行 file.CSV 的值循环?
- php - Wordpress Woocommerce 删除帐户用户名验证
- lua - Lua 解析并计算一个字符串
- python - 如何使用 Selenium 单击此链接?
- reactjs - 使用 React,在使用 react-transition-group 时,在 StrictMode 中不推荐使用 findDOMNode 作为警告
- jenkins - 在 Bitbucket Server 中管理 webhook
- kubernetes - helm 可以在单次运行中安装多组件应用程序吗?
- react-admin - 如何
和 在 react-admin 中自动向 Input 组件注入资源道具? - c# - 实体框架:自动计算成员