1. 程式人生 > >ElasticSearch6.0 索引模板

ElasticSearch6.0 索引模板

con settings create clas 6.0 self shelve category cse

我們在做es搜索的場合,每次創建索引的時候,都需要為每個索引設置mapping的字段映射,現在我們可以為通用的索引創建一個模板

每次創建索引時候,如果匹配到相應的模板 索引的mapping會被自動設置成模板的mapping配置

PUT  _template/temp_test
{
  "index_patterns": ["market*", "car*"],//匹配規則
  "settings": {
    "index.number_of_shards" : 5,  //分片數
    "number_of_shards": 1     //數據副本
  },
  "mappings": {
    "goods": {//索引類型
      "dynamic_templates": [
        {
          "dynamicFields": {//動態字段
            "match_mapping_type": "string",//動態字段匹配類型
             "path_match":"dynamicFields.*_sku_attr",//匹配規則
            "mapping":{
              "type": "keyword" //匹配的字段的類型映射
            }
          }
        }
      ],
       "properties":{ //普通字段的類型設置
        "id":{
           "type": "keyword"
        }, 
        "category_first_id":{
           "type": "keyword"
        }, 
        "category_first":{
           "type": "keyword"
        },
        "category_second_id":{
           "type": "keyword"
        },
        "category_second":{
           "type": "keyword"
        },
        "category_third_id":{
           "type": "keyword"
        },
        "category_third":{
           "type": "keyword"
        },
        "brand_id":{
           "type": "keyword"
        },
        "brand":{
           "type": "text",
           "analyzer":"ik_max_word",
           "search_analyzer":"ik_max_word",
           "copy_to":"full_name"
        },
        "shop":{
           "type": "keyword"
        },
        "attr_name":{
           "type": "keyword",
           "index":"true"
         
        },
        "sku":{
           "type": "keyword",
           "index":"true"
        },
        "spu":{
           "type": "keyword",
           "index":"true"
        },
        "gome_sku":{
           "type": "keyword"
        },
        "product_ch":{
           "type": "text",
           "analyzer":"ik_max_word",
           "search_analyzer":"ik_max_word",
           "copy_to":"full_name"
        },
        "adver":{
           "type": "keyword"
        },
        "product_img":{
           "type": "keyword"
        },
        "product_proto_price":{ 
           "type": "double"
        },
        "product_sale_price":{ 
           "type": "double"
        },
        "is_sku":{
           "type": "boolean"
        },
        "is_self":{
           "type": "boolean"
        },
        "shop_flag":{
           "type": "long"
        },
        "is_in_store":{
           "type": "boolean"
        },
        "is_shelves":{
           "type": "boolean"
        },
        "is_suit":{
           "type": "boolean"
        },
        "good_comment_rate":{ 
           "type": "long"
        },
        "sale_num":{
           "type": "long"
        },
        "spu_score":{
           "type": "long"
        },
        "dynamic_attrs":{
           "type": "keyword"
        },
        "full_name":{ 
           "type": "text",
           "store":"true"
        },
        "create_time":{
          "type":"date"
        }
      }
    }
  }
}

ElasticSearch6.0 索引模板