首页  

elasticsearch5.0搜索性能优化     所属分类 elasticsearch 浏览量 1340
根据原文翻译整理
https://www.elastic.co/guide/en/elasticsearch/reference/5.0/tune-for-search-speed.html




Give memory to the filesystem cache
Elasticsearch heavily relies on the filesystem cache in order to make search fast. 
In general, you should make sure that at least half the available memory 
goes to the filesystem cache so that elasticsearch can 
keep hot regions of the index in physical memory.


文件系统缓存 , 保留索引热点区域在内存


Use faster hardware
使用更快的硬件

更多的内存 文件系统缓存
SSD 

I/O bound
CPU-bound

Document modeling

Documents should be modeled so that search-time operations are as cheap as possible.
In particular, joins should be avoided. 
nested can make queries several times slower 
and parent-child relations can make queries hundreds of times slower. 
So if the same questions can be answered without joins by denormalizing documents, 
significant speedups can be expected.

文档建模
数据模型优化 
避免join  连接
嵌套会使查询速度慢几倍
父子关系会使查询速度慢上数百倍。

Pre-index data

You should leverage patterns in your queries to optimize the way data is indexed. 
For instance, if all your documents have a price field 
and most queries run range aggregations on a fixed list of ranges, 
you could make this aggregation faster by pre-indexing the ranges into the index 
and using a terms aggregations.

预先索引数据
在查询中利用模式来优化数据的索引方式。
价格  固定价格区间 聚合  预先索引
词聚合


PUT index/type/1
{
  "designation": "spoon",
  "price": 13
}

GET index/_search
{
  "aggs": {
    "price_ranges": {
      "range": {
        "field": "price",
        "ranges": [
          { "to": 10 },
          { "from": 10, "to": 100 },
          { "from": 100 }
        ]
      }
    }
  }
}

Then documents could be enriched by a price_range field at index time, which should be mapped 

PUT index
{
  "mappings": {
    "type": {
      "properties": {
        "price_range": {
          "type": "keyword"
        }
      }
    }
  }
}


PUT index/type/1
{
  "designation": "spoon",
  "price": 13,
  "price_range": "10-100"
}



And then search requests could aggregate this new field rather than running a range aggregation on the price field.

GET index/_search
{
  "aggs": {
    "price_ranges": {
      "terms": {
        "field": "price_range"
      }
    }
  }
}


Mappings
The fact that some data is numeric does not mean it should always be mapped as a numeric field. 
Typically, fields storing identifiers such as an ISBN 
or any number identifying a record from another database, 
might benefit from being mapped as keyword rather than integer or long.

映射优化
映射为关键字而不是整数或long,可能会受益。


Avoid scripts
In general, scripts should be avoided. 
If they are absolutely needed, you should prefer the painless and expressions engines.

避免脚本
painless 和 表达式引擎



查询缓存利用 

"filter": {
        "range": {
          "my_date": {
            "gte": "now-1h/m",
            "lte": "now/m"
          }
        }
      }

rounded to the minute
 


it might be tempting to split ranges into a large cacheable part 
and smaller not cacheable parts in order to be able to leverage the query cache

为了能够利用查询缓存,可能很容易将范围划分为大的可缓存部分和小的不可缓存部分
 
However such practice might make the query run slower in some cases 
since the overhead introduced by the bool query may defeat the savings from better leveraging the query cache.


然而,在某些情况下,这种做法可能会使查询运行得更慢,因为bool查询引入的开销可能会抵消更好地利用查询缓存带来的节省。


Force-merge read-only indices
Indices that are read-only would benefit from being merged down to a single segment. 
This is typically the case with time-based indices: 
only the index for the current time frame is getting new documents while older indices are read-only.


强制合并只读索引
基于时间的索引   最新的索引有写入 之前的索引时只读的

Warm up global ordinals

Global ordinals are a data-structure that is used in order to 
run terms aggregations on keyword fields. 
They are loaded lazily in memory because elasticsearch does not know 
which fields will be used in terms aggregations 
and which fields won’t. You can tell elasticsearch to load global ordinals 
eagerly at refresh-time by configuring mappings as described below:

PUT index
{
  "mappings": {
    "type": {
      "properties": {
        "foo": {
          "type": "keyword",
          "eager_global_ordinals": true
        }
      }
    }
  }
}

预热全局序号
用于 keyword 字段聚合
延迟加载 

Warm up the filesystem cache

If the machine running elasticsearch is restarted, 
the filesystem cache will be empty, 
so it will take some time before the operating system 
loads hot regions of the index into memory so that search operations are fast. 
You can explicitly tell the operating system 
which files should be loaded into memory eagerly depending on 
the file extension using the index.store.preload setting.

index.store.preload


Warning
Loading data into the filesystem cache eagerly on too many indices 
or too many files will make search slower if the filesystem cache 
is not large enough to hold all the data. Use with caution.

上一篇     下一篇
elasticsearch5.0搜索偏好

elasticsearch5.0的一般建议

elasticsearch5.0索引性能优化

elasticsearch5.0磁盘使用优化

plantUML安装使用

通过男女关系形象解读大数据技术