Renomeando campos na elasticsearch
Eu tenho um documento como este
{
"_index": "testindex",
"_type": "logs",
"_id": "1",
"_score": 1,
"_source": {
"field1": "data1",
"field2": "data2"
}
}
Eu preciso mudar ofield2
paraRequest.field3
{
"_index": "testindex",
"_type": "logs",
"_id": "1",
"_score": 1,
"_source": {
"field1": "data1",
"Request": {
"field3": "data2"
}
}
}
Para isso, primeiro foi adicionado um mapeamento de campo ao índice existente
PUT testindex/_mapping/logs
{
"properties":
{
"Request":
{
"properties":
{
"field3" :
{
"type": "string"
}
}
}
}
}
Então tentei reindexar
POST _reindex
{
"source": {
"index": "testindex"
},
"dest": {
"index": "testindex1"
},
"script": {
"inline": "ctx._source.Request.field3 = ctx._source.remove(\"field2\")"
}
}
O erro é
"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"
}