ElasticSearch 索引设置总结( 二 )


match_phrase 短语匹配
核心功能:match_phrase 查询首先将查询字符串解析成一个词项列表,然后对这些词项进行搜索; 只保留那些包含 全部 搜索词项,且 位置"position" 与搜索词 项相同的文档 。
应用场景:业务开发中 90%+ 的全文检索都会使用 match_phrase 或者 query_string 类型,而不是 match 。
适用类型:text 。
multi_match 多组匹配
核心功能:match query 针对多字段的升级版本 。
应用场景:多字段检索 。
适用类型:text 。
query_string 类型
核心功能:支持与或非表达式+其他N多配置参数 。
应用场景:业务系统需要支持自定义表达式检索 。
适用类型:text 。
bool 组合匹配
核心功能:多条件组合综合查询 。
【ElasticSearch 索引设置总结】应用场景:支持多条件组合查询的场景 。
适用类型:text 或者 keyword 。
一个 bool 过滤器由三部分组成:
must ——所有的语句都 必须(must) 匹配,与 AND 等价 。
must_not ——所有的语句都 不能(must not) 匹配,与 NOT 等价 。
should ——至少有一个语句要匹配,与 OR 等价 。f
ilter——必须匹配,运行在非评分&过滤模式 。
range范围搜索类型
适用类型:long,integer,double或者 date

  • Mapping 字段的参数设置

ElasticSearch 索引设置总结

文章插图
 
(1)index,倒排索引,not_analyzed,注意是否分词,尽量精简schema字段个数,不会被检索的字段就不要建立倒排 。.field("index", "no")
(2)doc values,正排索引,用于聚合或者排序
(3)norms,analyzed norms存储了多种正则化算子,用于docs的排序评分,如果不需要排序,可以disable norms
(4)index_options,有docs(文档有无), freqs(重复出现的文档评分更高), positions(涵盖了前2种,并且多了位置信息,用于临近查询), offsets(全部,用于高亮)四类
  • ES 索引template模板参考例子
PUT _template/test_template{"index_patterns": ["test_index_*","test_*"],"settings": {"number_of_shards": 1,"number_of_replicas": 1,"max_result_window": 100000,"refresh_interval": "30s"},"mappings": {"properties": {"id": {"type": "long"},"title": {"type": "keyword"},"content": {"analyzer": "ik_max_word","type": "text","fields": {"keyword": {"ignore_above": 256,"type": "keyword"}}},"available": {"type": "boolean"},"review": {"type": "nested","properties": {"nickname": {"type": "text"},"text": {"type": "text"},"stars": {"type": "integer"}}},"publish_time": {"type": "date","format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"},"expected_attendees": {"type": "integer_range"},"ip_addr": {"type": "ip"},"suggest": {"type": "completion"}}}}



推荐阅读