elasticsaerch DSL笔记

2021-10-22  本文已影响0人  DimonHo
# 为文档添加创建时间字段管道
PUT _ingest/pipeline/create_time-pipeline
    {
      "description": "文档创建时间",
      "processors": [
        {
          "set": {
            "field": "create_time",
            "value": "{{_ingest.timestamp}}"
          }
        }
      ]
    }
## 创建名称为wechat_msg-template的索引模板
PUT _template/wechat_msg-template
{
      "index_patterns": "wechat_msg-*",
      "order": 1,
      "settings": {
        "index.number_of_shards": 5,
        "index.number_of_replicas": 2,
        "index.mapping.coerce": false,
        "default_pipeline": "create_time_pipeline",  ## 为索引指定默认管道
        "analysis": {
          "analyzer": {
            "comma": {
              "type": "pattern",
              "pattern": ","
            }
          }
        }
      },
      "mappings": {
          "dynamic":"strict",
          "properties": {
              "create_time": {
                  "type": "date",
                  "format": "yyyy-MM-dd HH:mm:ss||date_optional_time"
              },
              "update_time": {
                  "type": "date",
                  "format": "yyyy-MM-dd HH:mm:ss||date_optional_time"
              },
              "app_id": {
                  "type": "keyword"
              },
              "original_id": {
                  "type": "keyword"
              },
              "open_id": {
                  "type": "keyword"
              },
              "nick_name": {
                  "type": "text",
                  "fields":{
                    "full":{
                      "type": "keyword"
                    }
                  }
              },
              "record_type": {
                  "type": "keyword"
              },
              "reply_type":{
                  "type": "keyword"
              },
              "message_type": {
                  "type": "keyword"
              },
              "event_type":{
                  "type": "keyword"
              },
              "event_key":{
                  "type": "keyword"
              },
              "is_read": {
                  "type": "boolean",
                  "null_value": false
              },
              "send_code": {
                  "type": "integer"
              },
              "err_msg": {
                  "type": "text"
              },
              "msg_id": {
                  "type": "long"
              },
              "mass_id":{
                  "type": "long"
              },
              "message_data": {
                  "type": "text"
              }
          }
      },
      "aliases": {
          "wechat_msg": {},
          "wechat_msg_all": {}
      }
    }
## 重建索引,并重命名字段名称
POST _reindex
{
  "source": {
    "index": "wechat_msg-2021.10"
  },
  "dest": {
    "index": "wechat_msg-2021.10.back"
  },
  "script": {
    "inline": "ctx._source.subscribe_task_id = ctx._source.remove('subscribe_fans_task_id');
               ctx._source.interactive_type = ctx._source.remove('activity_type');"
  }
}
## 添加字段
PUT wechat_msg-2021.11/_mapping
{
  "properties": {
    "id": {
      "type": "keyword"
    }
  }
}

## 给新添加的字段赋值
POST wechat_msg/_update_by_query
{
  "query": {
    "bool": {
      "must_not": [
        {
          "exists": {
            "field": "id"
          }
        }
      ]
    }
  },
  "script": {
    "source": "ctx._source['id'] = ctx._id"
  }
}
上一篇下一篇

猜你喜欢

热点阅读