mapping默認是集成於template的,固然若是mapping有設定的話,就走自定義的mapping.nginx
mapping至關於字段描述,好比某個字段是float,某個字段須要分詞,某個字段是date類型,是否能夠搜索bash
template,字面意思是模板,他所做的事情也是模板的事情,他能夠針對index作別名,也就是說,xiaorui* = xiaorui_v2_2013 xiaorui_v2_2014 … 通配符app
elasticsearch默認是字符串的類型的字段都會分詞的,通俗說,你使用elasticsearch query_string match均可以命中查詢的。elasticsearch
可是全部的字段分詞,他也會帶來性能及空間佔用問題,因此咱們只會針對特定的字段來進行開放分詞。ide
es在mapping默認的時候,會對nginx訪問日誌某些字段進行分詞,這樣變會致使nginx展現時字段表意不明。性能
能夠經過template自定義mapping,來解決此類問題ui
而mapping中字段屬性:"index": "not_analyzed",決定着該字段是否被分詞url
GET/_template 查看當前es系統全部的模板詳情spa
template_1 爲模板名日誌
PUT/_template/template_1 { "template":"t-*", "settings":{ "number_of_shards":1 }, "mappings":{ "type1":{ "_source":{ "enabled":false } } } }
PUT/_template/ dev-nginx-logs { "template": "dev-nginx-logs-*", "settings": { "number_of_shards": "5", "number_of_replicas": "1" }, "mappings": { "nginx_access_logs": { "properties": { "@timestamp": { "format": "dateOptionalTime", "type": "date", "index": "not_analyzed", "doc_values": true }, "status": { "type": "string", "index": "not_analyzed", "doc_values": true }, "upstreamhost": { "type": "string", "index": "not_analyzed", "doc_values": true }, "upstreamtime": { "type": "float" }, "url": { "type": "string", "index": "not_analyzed", "doc_values": true } } } } }