elasticsaerch DSL筆記

# 為文檔添加創(chuàng)建時(shí)間字段管道
PUT _ingest/pipeline/create_time-pipeline
    {
      "description": "文檔創(chuàng)建時(shí)間",
      "processors": [
        {
          "set": {
            "field": "create_time",
            "value": "{{_ingest.timestamp}}"
          }
        }
      ]
    }
## 創(chuàng)建名稱(chēng)為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",  ## 為索引指定默認(rèn)管道
        "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": {}
      }
    }
## 重建索引,并重命名字段名稱(chēng)
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"
  }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 今天青石的票圈出鏡率最高的,莫過(guò)于張藝謀的新片終于定檔了。 一張滿溢著水墨風(fēng)的海報(bào)一次次的出現(xiàn)在票圈里,也就是老謀...
    青石電影閱讀 10,784評(píng)論 1 2
  • 一、jQuery簡(jiǎn)介 JQ是JS的一個(gè)優(yōu)秀的庫(kù),大型開(kāi)發(fā)必備。在此,我想說(shuō)的是,JQ里面很多函數(shù)使用和JS類(lèi)似,所...
    Welkin_qing閱讀 12,787評(píng)論 1 6
  • 字符串 1.什么是字符串 使用單引號(hào)或者雙引號(hào)括起來(lái)的字符集就是字符串。 引號(hào)中單獨(dú)的符號(hào)、數(shù)字、字母等叫字符。 ...
    mango_2e17閱讀 7,750評(píng)論 1 7
  • 一場(chǎng)說(shuō)走就走的旅行。 簡(jiǎn)單地整理幾件必備旅行用品,7.18日早上8.00準(zhǔn)時(shí)出發(fā)了,計(jì)劃一路南下然后繞西南一圈回恩...
    悠游魚(yú)閱讀 3,649評(píng)論 3 6
  • 原來(lái)看過(guò)一段話,第一厲害的人有能力沒(méi)脾氣,第二厲害的人有能力有脾氣,最差的是沒(méi)能力有脾氣的人。 以我最...
    涼風(fēng)豆豆閱讀 1,629評(píng)論 2 0

友情鏈接更多精彩內(nèi)容