elastic search

es新增字段并赋值

2020-12-13  本文已影响0人  修行者12138

原mappings如下

{
    "audit_demo_bak": {
        "mappings": {
            "_doc": {
                "properties": {
                    "full_name": {
                        "type": "text",
                        "analyzer": "ik_max_word"
                    }
                }
            }
        }
    }
}

想要新增full_name_copy字段,类型为keyword,并初始化值为full_name

步骤1 新增字段

PUT {{di}}/audit_demo/_doc/_mapping
{
    "properties": {
        "full_name_copy": {
            "type": "keyword"
        }
    }
}

步骤2 使用painless赋值

POST {{di}}/audit_demo/_update_by_query
{
    "script": {
        "lang": "painless",
        "inline": "ctx._source.full_name_copy = ctx._source.full_name"
    }
}
上一篇 下一篇

猜你喜欢

热点阅读