赞
踩
es 版本为7.9.3
POST test { "mappings" : { "properties" : { "name" : { "type" : "text", "fields" : { "keyword" : { "type" : "keyword", "ignore_above" : 256 } } } } } } POST test/_doc/1 { "name": "chb", "age": "20" } POST test/_doc/2 { "name": "ling", "age": 18 } POST test/_doc/3 { "name": "旺仔", "age": 1 } POST test/_doc/4 { "name": "李四" }
# 修改李四的年龄为44 POST test/_update_by_query { "script": { "source": "ctx._source.age = 44", "lang": "painless" }, "query": { "bool": { "must_not": [ { "exists": { "field": "age" } } ] } } }
修改mapping,添加一个子字段
POST test/_mapping { "properties": { "name": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 }, "ik_smart": { "type": "text", "analyzer": "ik_smart" } } } } }
插入一条新的数据
PUT test/_doc/5
{
"name": "王五",
"age": 35
}
查询 李四,王五,发现查不到李四
GET test/_search { "query": { "match": { "name.ik_smart": "李四" } } } GET test/_search { "query": { "match": { "name.ik_smart": "王五" } } }
因为李四是 更改mapping之前插入,新增字段没有在老数据上生效,导致查询不出
为了之前的数据也能被查询到,我们通过 _update_by_query
POST test/_update_by_query
结果可以查询
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。