mappingweb
映射定义了一个文档和其包含的数据如何被索引到elasticsearch中的规则,哪些字段是数字,哪些字段是字符串,哪些字段是时间格式登,定义字符串字段的分析器,定义时间字段的格式等json
获取或者更新一个索引或者类型的映射为_mappingapp
GET http://localhost:9200/website/blog/_mapping { "bbs": { "mappings": { "thread": { "properties": { "city_id": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "content": { "type": "text", "analyzer": "ik_smart" }, "forum_id": { "type": "long" }, "publish_time": { "type": "date", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" }, "reply_count": { "type": "long" }, "thread_id": { "type": "long" }, "title": { "type": "text", "analyzer": "ik_smart" }, "user_id": { "type": "long" }, "username": { "type": "text" } } } } } }
设置elasticsearch
PUT http://localhost:9200/website/blog/_mapping { "bbs": { "mappings": { "thread": { "properties": { "city_id": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "content": { "type": "text", "analyzer": "ik_smart" }, "forum_id": { "type": "long" }, "publish_time": { "type": "date", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" }, "title": { "type": "text", "analyzer": "ik_smart" }, "user_id": { "type": "long" }, "username": { "type": "text" } } } } } }
属性的类型:this
文本格式,索引时,会根据设置的分析器,分词,处理字符串,分红适合于倒排索引的独立的词条code
analyzer: 设置分析器,在索引时和搜索时(无设置search_analyzer时)会被用来处理字符串, 默认为standard search_analyzer: 设置搜索分析器,在搜索时用来处理字符串 boost: 设置字段相关性权重,搜索时影响权重值 index: 设置字段是否能够搜索 analyzed 首先分析字符串,而后索引它。换句话说,以全文索引这个域。 not_analyzed 索引这个域,因此能够搜索到它,但索引指定的精确值。不对它进行分析。 no Don’t index this field at all不索引这个域。这个域不会被搜索到。 norms: 设置字段查询相关度是否受字段长度影响 默认true
ignore_above: 索引的最长长度
format:格式("yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis")