• 记录一次painless script


    //添加一条记录
    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
  • 相关阅读:
    【BZOJ】2019: [Usaco2009 Nov]找工作(spfa)
    【BZOJ】3668: [Noi2014]起床困难综合症(暴力)
    Redis 字符串结构和常用命令
    Redis实现存取数据+数据存取
    Spring 使用RedisTemplate操作Redis
    使用 java替换web项目的web.xml
    SQL server 从创建数据库到查询数据的简单操作
    SQL server 安装教程
    IntelliJ IDEA 注册码(因为之前的地址被封杀了,所以换了个地址)
    对程序员有帮助的几个非技术实用链接(点我,你不会后悔的)
  • 原文地址:https://www.cnblogs.com/beaconSky/p/12194300.html
Copyright © 2020-2023  润新知