首页  

Elasticsearch性能优化建议     所属分类 elasticsearch 浏览量 880
不要返回较大的结果集
返回大量文档使用Scroll

避免稀疏 
避免将不相关的数据放到同一索引中 
稀疏字段上不要使用norms和doc_values

批量索引 bulk  
来不及索引  TOO_MANY_REQUESTS 和 EsRejectedExecutionException

增加刷新间隔
index.refresh_interval 默认1s,可以改成30s 减少合并压力

加载大量数据时暂停refresh和repliccas
index.refresh_interval=-1 
index.number_of_replicas=0

禁用swapping

给文件缓存预留足够内存

使用更好的硬件  譬如 SSD

索引缓冲大小
indices.memory.index_buffer_size 通常是JVM的0.1,确保足够处理至多512MB的索引

避免join
实现join的两种方式  nested  parent和child

文档建模优化 ,适当冗余

预索引数据
譬如根据时间增加 按天 按月的字段

避免scripts
如果一定要使用,推荐painless和expressions

强制合并只读索引
https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-forcemerge.html


不需要过滤时禁用索引  index:false
不需要text字段的score,禁用norms  norms:false
不需要短语查询可以不索引positions    indexe_options:freqs

禁用_all 字段

使用best_compression

使用最小的足够用的数值类型

byte,short,integer,long
half_float,float,double

使用routing

jvm  Don’t Cross 32 GB!

按业务拆分 索引拆分 集群拆分

text和keyword ,text写入时会分词 ,没有分词需求,使用keyword 
number  和 keyword ,数值类型,提高range query的查询速度,keyword类型,提高 term query 的查询速度
没有 range query 需求,使用  keyword 

doc_values  列式存储,支持高效的排序和聚合 
字段若没有排序和聚合需求,可以禁用doc_values

_source 字段  存储原始json文档,默认包含所有字段 ,可按需裁剪
_soucrce 中配置 includes 和 excludes 


建议禁用dynamic mapping   , 可通过dynamic_templates预设数据类型




Elasticsearch _all字段 elasticsearch 优化点 https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-create-index.html#mappings https://www.elastic.co/guide/en/elasticsearch/reference/master/index-modules.html#dynamic-index-settings https://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html

上一篇     下一篇
一份牛逼的简历模板

云原生四要素

linux实用命令合集

动物英语单词

哈佛训言

费曼学习法:输出是最好的学习