弹性搜索在重新索引期间出现无痛的脚本问题



我想将geoip的旧数据重新索引到地理点。

以前的数据包含此格式的位置。

"geoip": {
    "location": {
        "lon": 67.0703,
        "lat": 24.9206
    }
} 

我想像这样在数组中的地理点中重新索引位置

"geoip": {
    "location": [lon, lat]
} 

这是映射

PUT logs-audit-geopoint/_mapping/doc
{
  "properties": {
    "json":{
      "properties": {
        "geoip":{
          "properties":{
            "location": {
              "type": "geo_point"
            }
          }
        }
      }
    }
  }
}

这是我执行重新索引的请求。

POST _reindex
{
  "source": {
    "index": "logs-audit"
  },
  "dest": {
    "index": "logs-audit-geopoint"
  },
  "script": {
     "source": "def geoip = ctx._source.json.geoip; if(geoip != null) { geoip.location = [geoip.longitude, geoip.latitude]; }",
      "lang": "painless"
    }
}

问题它不会覆盖位置:{} 到位置:[]

使用临时索引来转换数据:

日志审计(来源(
测试(临时(
logs-audit-geopoint(destination(

迁移过程分步进行:

1-从源索引[日志审计]传输到[测试]索引(空,与 无映射(与新变量location_new。

    POST _reindex
    {
      "source": {
        "index": "logs-audit"
      },
      "dest": {
        "index": "test"
      },
      "script": {
         "source": "def geoip = ctx._source.json.geoip; if(geoip != null && geoip != '' ) { geoip.location = null; geoip.location_new = [geoip.longitude, geoip.latitude] }",
          "lang": "painless"
        }
    }

2-使用以下映射创建新索引(geoip.location = geo_point(

    PUT logs-audit-geopoint/_mapping/doc
    {
      "properties": {
        "json":{
          "properties": {
            "geoip":{
              "properties":{
                "location": {
                  "type": "geo_point"
                }
              }
            }
          }
        }
      }
    }

3-然后从测试索引转移到新索引。

    POST _reindex
    {
      "source": {
        "index": "test"
      },
      "dest": {
        "index": "logs-audit-geopoint"
      },
      "script": {
         "source": "def geoip = ctx._source.json.geoip; if(geoip != null && geoip != '' ) { geoip.location = geoip.location_new }",
          "lang": "painless"
        }
    }

最新更新