分析是文档被发送并加入倒排索引之前,es在其主体上进行的操作,具体如下
1.字符过滤-使用字符过滤器转变字符
2.文本切分为分词-将文本切分为单个或多个分词
3,分词过滤-使用分词过滤器转变每个分词
4.分词索引-将这些分词存储到索引中
为文档使用分析器
1.当创建索引的时候,为特定的索引进行设置-直接生效
2.在es配置文件中,设置全局分析器-需重启生效
在映射中指定某个字段的分析器
#为description字段指定myCustomerAnalyzer分析器
{"mappings": {"document":{"properties":{"description":{"type":"string","analyzer":"myCustomerAnalyzer"}}}}
}
#指定不要分析description字段
{"mappings": {"document":{"properties":{"description":{"type":"string","index":"not_analyzed"}}}}
}
使用分析API来分析文本
curl -XPOST 'localhost:9200/_analyze' -H 'Content-Type: application/json' -d '{"analyzer": "standard","text": "share your experience with NoSql & big data technologies"
}'