← tanscp

Elasticsearch

尝试修复Elasticsearch中出现的“Too many dynamic script compilations”错误

· 发表评论

背景

有个业务接口使用es template模板搜索,模板比较复杂。同时在代码中使用java的velocity模板引擎来解析填充搜索关键词。最早使用Elasticsearch 5没有出现动态编译报错,在升级到Elasticsearch 7.10.2版本后,会偶发出现超过动态编译数量限制的错误,如下:

{
    "type": "circuit_breaking_exception",
    "reason": "[script] Too many dynamic script compilations within, max: [75/5m];
                please use indexed, or scripts with parameters instead; 
                this limit can be changed by the [script.context.template.max_compilations_rate] setting",
    "bytes_wanted": 0,
    "bytes_limit": 0,
    "durability": "TRANSIENT"
}

Elasticsearch在执行查询时达到脚本编译限制,抛出circuit_breaking_exception错误,并且查询不会运行。这个错误通常是由于在短时间内编译了太多的动态脚本而导致的。需要优化代码以减少编译次数,或者增加编译次数的限制。可以尝试将动态脚本缓存起来,以便在需要时可以重复使用,从而减少编译次数。

Clickhouse vs MongoDB: What are the differences?

· 发表评论

Introduction

In this article, we will discuss the key differences between ClickHouse and MongoDB, two popular database management systems. Both ClickHouse and MongoDB have their own unique features and characteristics that make them suitable for different use cases.

Let's explore the differences between these two databases.

Elasticsearch 查询过程中的 pre-filter 原理

· 发表评论

大家都知道在对索引执行查询的时候,需要在所有的分片上执行查询,因为无法知道被查询的关键词位于哪个分片,对于全文查询来说诚然如此,然而对于时序型的索引,当你从 my_index-* 中执行 now-3d 的范围查询时,可能很多分片上都不存在被查询的数据范围,因此 es 从 v5.6 开始引入了 pre-filter 机制:对于 Date 类型的 Range 查询,在对分片执行搜索之前,先检查一下分片是否包括被查询的数据范围,如果查询的范围与分片持有的数据没有交集,就跳过该分片。

分布式搜索过程原先由两个阶段执行:查询阶段和取回阶段,在引入了 pre-filter 之后,分布式搜索过程变成了三个阶段:预过滤阶段(pre-filter)、查询阶段和取回阶段。pre-filter 在查询阶段之前执行。

Lucene评分算法解释

· 发表评论

Lucene 的 IndexSearcher 提供一个 explain 方法,能够解释 Document 的 Score 是怎么得来的,具体每一部分的得分都可以详细地打印出来。这里用一个中文实例来纯手工验算一遍 Lucene 的评分算法,并且结合 Lucene 的源码做一个解释。