gpt4 book ai didi

elasticsearch - 重新索引期间的 Elasticsearch 无痛脚本问题

转载 作者:行者123 更新时间:2023-12-03 01:39:15 25 4
gpt4 key购买 nike

我想将geoip的旧数据重新索引到geopoint。

previous data contains location in this format.


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

I want to re-index location in geo point in array like this


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

this is mapping


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

this is my request to perform re indexing.


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(source)
test(temporary)
logs-audit-geopoint(destination)



迁移过程:

1- Transfer from source index [logs-audit] to [test] index(empty with no mapping) with new variable 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- Create new index with following mapping(geoip.location = geo_point)


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

3- Then transfer from test index to new index.


    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"
}
}

关于elasticsearch - 重新索引期间的 Elasticsearch 无痛脚本问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49363792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com