映射和分析
GET /_search?q=2014-09-15
GET /_search?q=date:2014-09-15
# 查看映射文档结构
# 数据类型:text、date、long、boolean、float、double、short、byte、integer
GET /gb/_mapping/tweet
# 分析器:字符过滤器、分词器、Token过滤器
# 内置分析器:标准分析器、简单分析器、空格分析器、语言分析器
# 标准分析器:单词边界划分文本,删除绝大多数标点,将词条小写
# 简单分析器:从任何不是字母的地方划分文本,将词条小写
# 空格分析器:以空格划分文本
# 语言分析器:英语分析器将提取词干,去除英语无用词(the and)
# date域包含精确值,而文本域划分词条
# 查询和倒排索引均会用到分析器进行划分词条
# 分析器示例
GET /_analyze
{
"analyzer": "standard",
"text": "Text to analyzer"
}
# 自定义域映射
# 属性:type、index、analyzer
# type : text、date、long、boolean、float、double、short、byte、integer、keyword
# index : analyzed(分析索引)、not_analyzed(不分析索引)、no(不分析不索引)
# string类型,默认为analyzed,其他类型只支持not_analyzed、no,永远不会被分析
# analyzer : 只支持string类型,默认为stardard
# 自定义gb索引的mapping
PUT /gb
{
"mappings": {
"tweet":{
"properties":{
"tweet":{
"type":"text",
"analyzer":"english"
},
"date":{
"type":"date"
},
"name":{
"type":"text"
},
"user_id":{
"type":"long"
}
}
}
}
}
# 修改gb索引的mapping,只能增加域,不能修改已存在的域
PUT /gb/_mapping/tweet
{
"properties": {
"tags":{
"type":"keyword"
}
}
}
# 测试gb中域使用的analyze
GET /gb/_analyze
{
"field": "tweet",
"text": "Black-cats"
}
GET /gb/_analyze
{
"field": "tags",
"text":"Black-cats"
}