//添加一条记录
PUT /dark-soul/_doc/1
{
"owner": "omwNIByhrz",
"common_data": {
"testdx01_field_neizhi01": {
"builtInType": "provinceCity"
},
"testdx01_field_duoxuan": [
"bj1"
],
"testdx01_field_danxuan": [
"beijin"
],
"testdx01_field_tupian": [],
"testdx01_field_wenben": "中文05"
}
}
//查询mapping
GET /dark-soul/_mapping
{
"dark-soul" : {
"mappings" : {
"properties" : {
"common_data" : {
"properties" : {
"testdx01_field_danxuan" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"testdx01_field_duoxuan" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"testdx01_field_neizhi01" : {
"properties" : {
"builtInType" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"testdx01_field_wenben" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"ext" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"ext1" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"ext2" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"owner" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
//使用painless脚本
POST /dark-soul/_update_by_query
{
"query": {
"match_all": {}
},
"script": {
"source": """
ctx._source.ext = ctx._source.common_data.toString();
String result = "";
for(entry in ctx._source.common_data.entrySet()){
if (entry.getValue() instanceof List) {
result += "";
continue;
} else if (entry.getValue() instanceof Map) {
if (entry.getValue().get("displayValue") != null && entry.getValue().get("displayValue") != "") {
result += (String)entry.getValue().get("displayValue") + " ";
}
continue;
} else if(entry.getValue() != null && entry.getValue() != ""){
result += entry.getValue().toString() + " ";
continue;
}
result += "";
}
ctx._source.ext2 = result;
""",
"lang": "painless"
}
}
//查询变更后的记录
GET /dark-soul/_doc/1