如果我们每天都要新建索引,而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