我有这样重命名字段
{
"_index": "testindex",
"_type": "logs",
"_id": "1",
"_score": 1,
"_source": {
"field1": "data1",
"field2": "data2"
}
}
文档我需要改变field2
到Request.field3
{
"_index": "testindex",
"_type": "logs",
"_id": "1",
"_score": 1,
"_source": {
"field1": "data1",
"Request": {
"field3": "data2"
}
}
}
为此,首先添加一个字段映射到现存的索引
PUT testindex/_mapping/logs
{
"properties":
{
"Request":
{
"properties":
{
"field3" :
{
"type": "string"
}
}
}
}
}
然后尝试重新索引
POST _reindex
{
"source": {
"index": "testindex"
},
"dest": {
"index": "testindex1"
},
"script": {
"inline": "ctx._source.Request.field3 = ctx._source.remove(\"field2\")"
}
}
错误是
"reason": "failed to run inline script [ctx._source.Request.field3 = ctx._source.remove(\"field2\")] using lang [groovy]",
"caused_by": {
"type": "null_pointer_exception",
"reason": "Cannot set property 'field3' on null object"
}
谢谢@ saeed-zhiany格式化.. –