拥有数百亿个文件。文档的一个字段是时间戳(毫秒),在建立索引时使用以下映射。
timestamp:
type: "date"
format: "YYYY-MM-dd HH:mm:ss||YYYY-MM-dd HH:mm:ss.SSS"
ignore_malformed: true
doc_values: true
搜索时,请使用范围过滤器。由于使用了doc_value,因此范围过滤器在内部使用反向索引进行搜索。这有点慢。
The execution option controls how the range filter internally executes. The execution option accepts the following values: index: Uses the field’s inverted index in order to determine whether documents fall within the specified range.
如果我以另一种方式更改映射,即使用天而不是小时/秒/毫秒。
day:
type: "date"
format: "YYYY-MM-dd"
ignore_malformed: true
doc_values: true
搜索时,使用范围过滤器,速度更快。
有人可以帮忙解释一下为什么性能有所不同。
第一个(使用秒/毫秒),反向索引(内部认为是哈希表)具有大量键。虽然第二个(仅使用几天),但反向索引的键要少得多。
是这个原因吗?
最佳答案
您的假设是正确的。如果未索引日期的时间分量,则唯一值的数量会减少。在进行范围查询时,Elasticsearch必须“循环”较少数量的发布列表,因此可以观察到性能提高。
关于filter - Elasticsearch范围过滤器倒排索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30281039/