Tôi có một tài liệu như thế nàylĩnh vực Đổi tên trong elasticsearch
{
"_index": "testindex",
"_type": "logs",
"_id": "1",
"_score": 1,
"_source": {
"field1": "data1",
"field2": "data2"
}
}
tôi cần phải thay đổi field2
để Request.field3
{
"_index": "testindex",
"_type": "logs",
"_id": "1",
"_score": 1,
"_source": {
"field1": "data1",
"Request": {
"field3": "data2"
}
}
}
Đối với điều này, đầu tiên thêm một ánh xạ trường để chỉ số hiện tại
PUT testindex/_mapping/logs
{
"properties":
{
"Request":
{
"properties":
{
"field3" :
{
"type": "string"
}
}
}
}
}
Sau đó, thử reindexing
POST _reindex
{
"source": {
"index": "testindex"
},
"dest": {
"index": "testindex1"
},
"script": {
"inline": "ctx._source.Request.field3 = ctx._source.remove(\"field2\")"
}
}
Lỗi là
"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"
}
cảm ơn @ saeed-zhiany để định dạng .. –