码迷,mamicode.com
首页 > 其他好文 > 详细

记录一次painless script

时间:2020-01-14 22:19:08      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:set   try   test   play   instance   common   使用   code   添加   

//添加一条记录
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

记录一次painless script

标签:set   try   test   play   instance   common   使用   code   添加   

原文地址:https://www.cnblogs.com/beaconSky/p/12194300.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!