在使用ES时,我们常见的就是需要生成一个template来定义索引的设置,分词器,MApping.本文将基于项目经验来总结一些常用的配置 。
Index设置
- index.refresh_interval
- number_of_replicas
- index.number_of_shards
- index.max_result_window
- index.store.preload
- index.sort.field 和 index.sort.order
{"settings" : {"index" : {"sort.field" : "date",// 字段名字"sort.order" : "desc"// 升序 asc 和降序 desc}}}
Mapping设置- 动态映射
{"mappings": {"_doc": {"dynamic_templates": [{"strings_as_keywords": {"match_mapping_type": "string","mapping": {"type": "keyword"}}}],"_source": {"enabled": true},"properties": {.....}}}}
- 字段类型
a simple type like text, keyword, date, long, double, boolean or ip.
a type which supports the hierarchical nature of JSON such as object or nested.
or a specialised type like geo_point, geo_shape, or completion.
- 常见的类型和搜索类型的联系
(2)keyword 类型:无需分词、整段完整精确匹配 。适用于:email 地址、住址、状态码、分类 tags 。
- 常见的搜索类型使用的字段类型
核心功能:不受到分词器的影响,属于完整的精确匹配 。
应用场景:精确、精准匹配 。
适用类型:keyword 。
prefix 前缀匹配
核心功能:前缀匹配 。
应用场景:前缀自动补全的业务场景 。
适用类型:keyword 。
wildcard 模糊匹配
核心功能:匹配具有匹配通配符表达式 keyword 类型的文档 。支持的通配符:*,它匹配任何字符序列(包括空字符序列);?,它匹配任何单个字符 。
应用 场景:请注意,选型务必要慎重!此查询可能很慢多组关键次的情况下可能会导致宕机,因为它需要遍历多个术语 。为了防止非常慢的通配符查询,通配符 不能以任何一个通配符*或?开头 。
match 分词匹配
核心功能:全文检索,分词词项匹配 。
应用场景:实际业务中较少使用,原因:匹配范围太宽泛,不够准确 。
适用类型:text 。
推荐阅读
- 电脑虚拟内存怎么设置,教您怎么设置?电脑虚拟内存一般怎么设置?
- iphone 6s虚拟home键怎么打开?苹果6虚拟home键怎么设置方法?
- win10怎么一键网络共享
- 「系统架构」Elasticsearch是如何保证数据的一致性和实时性的
- 还不知道MySQL怎么给字符串加索引?
- 电脑用久了越来越卡?现在调整这3个设置,立马流畅好几倍
- iPhone 备忘录如何设置密码
- 用于相似图片搜索引擎的Python OpenCV图像直方图
- 华为mate10如何设置双系统?华为mate10双屏幕怎么设置?
- Mysql索引为什么使用B+树而不使用跳表?