ElasticSearch6.0 索引模板

我们在做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"
        }
      }
    }
  }
}

 

转载于:https://www.cnblogs.com/shoutn/p/8274893.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值