Renaming fields in elasticsearch

后端 未结 2 1167
醉梦人生
醉梦人生 2020-12-20 18:01

I have a document like this

{
    \"_index\": \"testindex\",
    \"_type\": \"logs\",
    \"_id\": \"1\",
    \"_score\": 1,
    \"_source\": {
      \"field         


        
2条回答
  •  一个人的身影
    2020-12-20 18:15

    The Request field does not yet exist in your documents, so your script needs to create it first:

    POST _reindex
    {
        "source": {
            "index": "testindex"
        },
        "dest": {
            "index": "testindex1"
        },
        "script": {
            "inline": "ctx._source.Request = [:]; ctx._source.Request.field3 = ctx._source.remove(\"field2\") ]"
        }
    }
    

    Or a bit shorter like this:

    POST _reindex
    {
        "source": {
            "index": "testindex"
        },
        "dest": {
            "index": "testindex1"
        },
        "script": {
            "inline": "ctx._source.Request = [field3: ctx._source.remove(\"field2\") ]"
        }
    }
    

提交回复
热议问题