首页  

elasticsearch使用7大原则     所属分类 elasticsearch 浏览量 906
使用好的硬件
SSD硬盘 CPU 内存 
内存  64G以上 堆最大内存31G(不要超过32G) ,预留足够内存给文件系统缓存


集群部署 maste节点 data节点 Coordinating节点 Ingest Node(预处理节点) 集群较大时 一般设置3个专用的maste节点 discovery.zen.minimum_master_nodes 设置, 防止脑裂 N/2+1(N为候选master节点数) 索引冷热分离 协调节点 聚合各分片或各节点返回的数据 需要较好的CPU和较高的内存 设置 node.master node.data node.ingest 都为false 禁用 ingest 设置 node.ingest 为false
内存设置 lucene 利用操作系统内存来缓存索引数据 内存小于64G,50%给ES,50%留给lucene 堆最大内存不要超过32G 内存大于64G 聚合或排序 全文检索 禁用swap JVM锁定内存 bootstrap.memory_lock: true GC建议使用默认的 Concurrent-Mark and Sweep (CMS) 线程池 使用默认配置
集群分片设置 索引创建后无法修改分片 一个分片对应一个lucene索引 ,分片数不能设置过大 每个分片占用的硬盘容量不超过JVM最大堆内存 (不超过32G) 500G索引,分片数16个左右 分片数不超过节点数的3倍
Mapping 设置 避免使用nested或parent/child , nested query慢,parent/child query更慢 可采用 大宽表设计 每一个nested field,都会生成一个独立的document,Doc数量剧增,影响查询效率,尤其是JOIN的效率 避免动态mapping 控制索引的字段数量、mapping深度、索引字段的类型 index.mapping.nested_objects.limit :10000 index.mapping.total_fields.limit:1000 index.mapping.depth.limit: 20
索引优化 refresh_interval=-1 number_of_replicas=0 indices.memory.index_buffer_size:10%(默认) indices.memory.min_index_buffer_size: 48mb(默认) indices.memory.max_index_buffer_size translog设置 index.translog.sync_interval:5s(默认) index.translog.flush_threshold_size:512mb(默认) 建议使用ES的默认ID生成策略或使用数字类型ID 禁用_all字段 _source字段 includes excludes index属性,analyzed not_analyzed
查询优化 query_string或multi_match的查询字段越多, 查询越慢。 可在mapping阶段,利用copy_to属性将多字段的值索引到一个新字段,multi_match时,用新字段查询。 query cache 限制结果集大小 避免使用script 避免层级过深的聚合查询 预索引 譬如 年龄分组 增加 age_group字段 不用age做range aggregations,通过age_group字段就可以 filter查询会使用query cache ,过滤查询比较多可把 query cache 设大 indices.queries.cache.size: 10%(默认) 可设置成百分比,也可设置成具体值,如256mb 可禁用查询缓存(默认开启) index.queries.cache.enabled:false FieldDataCache indices.fielddata.cache.size ShardRequestCache index.requests.cache.enable shard request cache只缓存hits.total, aggregations, suggestions类型的数据,并不会缓存hits的内容 indices.requests.cache.size

上一篇     下一篇
分布式事务六种解决方案

elasticsearch禁用自动创建索引和类型

Elasticsearch 搜索 分词器 过滤器

elasticsearch profile 使用简介

Elasticsearch聚合分析简介

elasticsearch 查询 DSL 指定分词器