ElasticSearch之动态mapping模板

如果我们每天都要新建索引,而mapping需要提前设置,这个时候就需要用到动态模板;每日凌晨新建索引时,匹配template的索引即可自动创建mapping。

下面有个模板的例子,供大家参考:

(只要匹配news_wordcloud*的索引即可自动创建type为cms的mapping)

#模板
curl -XPUT localhost:9200/_template/template_news_wordcloud -d '  
{  
    "template" : "news_wordcloud*",  
    "settings": { 
        "number_of_shards": 3, 
        "number_of_replicas": 1, 
        "index.refresh_interval": "1s", 
        "index.translog.flush_threshold_ops": "100000" 
    },
   "aliases" : {  
        "news_wordcloud" : {}
    },
    "mappings" : {  
    "cms":{
          "_source": {"compress": true},
          "properties":
                {"id": {
                    "type": "string", 
                    "index" : "no"
                },
                "rowkey": {
                    "type": "string", 
                    "index" : "no"
                },
                "news_url": {
                    "type" : "multi_field",
                   "fields" : {
                    "news_url" : {"type" : "string", "index" : "no"},
                    "snews_url" : {"type" : "string", "index" : "not_analyzed"}
                    }
                },
                "news_content": {
                   "type" : "multi_field",
                   "fields" : {
                    "news_content" : {"type" : "string", "index" : "analyzed"}
                    }
                },
                "news_type": {
                  "type" : "multi_field",
                   "fields" : {
                    "news_type" : {"type" : "string", "index" : "no"},
                    "snews_type" : {"type" : "string", "index" : "not_analyzed"}
                    }
                },
                "news_time": {
                 "type" : "multi_field",
                   "fields" : {
                    "news_time" : {"type" : "string", "index" : "no"},
                    "snews_time" : {"type" : "string", "index" : "not_analyzed"}
                    }
                },
                "news_desc": {
                    "type" : "multi_field",
                   "fields" : {
                    "news_desc" : {"type" : "string", "index" : "analyzed"},
                    "snews_desc" : {"type" : "string", "index" : "not_analyzed"}
                    }
                },
               "sources": {
                  "type" : "multi_field",
                   "fields" : {
                    "sources" : {"type" : "string", "index" : "no"},
                    "ssources" : {"type" : "string", "index" : "not_analyzed"}
                    }
                },
               "news_classify": {
                  "type" : "multi_field",
                   "fields" : {
                    "news_classify" : {"type" : "string", "index" : "no"},
                    "snews_classify" : {"type" : "string", "index" : "not_analyzed"}
                    }
                },
               "partion_day": {
                  "type" : "multi_field",
                   "fields" : {
                    "partion_day" : {"type" : "string", "index" : "not_analyzed"}              
                    }
                }
            }}
                
          }
    }  
}'  


本文出处:http://blog.csdn.net/shan1369678/article/details/51446236


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值