在elasticsearch中指定可以执行匹配的值数量的最大限制是多少?我在某处读到它是 1024 但也是可配置的。真的吗?它如何影响性能?
curl -XPOST 'localhost:9200/my_index/_search?pretty' -d '{
"query": {
"filtered": {
"filter": {
"not": {
"ids": {
"type": "my_type",
"values": ["1", "2", "3"]
}}}}}}'
我可以在此数组中指定多少个值?极限是多少?如果是可配置的,增加限制对性能有何影响?
我认为 Elaticsearch 或 Lucene 没有明确设置任何限制。不过,您可能会遇到的限制是 JDK 设置的限制。
为了证明我上面的说法,我查看了Elasticsearch的源码:
当请求到来时有一个解析器可以解析 ids 数组 https://github.com/elasticsearch/elasticsearch/blob/1.x/src/main/java/org/elasticsearch/index/query/IdsFilterParser.java#L55。它所使用的只是一个ArrayList
。然后将其传递给 Lucene,Lucene 又使用列表。
这是 LuceneTermsFilter 类 http://search-lucene.com/c/Lucene:queries/src/java/org/apache/lucene/queries/TermsFilter.java%7C%7C+public+TermsFilter%2528final+String+field%252C+final+List+terms%2529(第 #84 行)从列表中的 Elasticsearch 获取 IDS 列表。
的源代码ArrayList
Oracle JDK 1.7.0_67 中的类:
/**
* The maximum size of array to allocate.
* Some VMs reserve some header words in an array.
* Attempts to allocate larger arrays may result in
* OutOfMemoryError: Requested array size exceeds VM limit
*/
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
/**
* Increases the capacity to ensure that it can hold at least the
* number of elements specified by the minimum capacity argument.
*
* @param minCapacity the desired minimum capacity
*/
private void grow(int minCapacity) {
...
if (newCapacity - MAX_ARRAY_SIZE > 0)
newCapacity = hugeCapacity(minCapacity);
...
}
private static int hugeCapacity(int minCapacity) {
if (minCapacity < 0) // overflow
throw new OutOfMemoryError();
return (minCapacity > MAX_ARRAY_SIZE) ?
Integer.MAX_VALUE :
MAX_ARRAY_SIZE;
}
还有那个数字(Integer.MAX_VALUE - 8
) is 2147483639
。因此,这将是该数组的理论最大大小。
我在我的 ES 实例中本地测试了 150000 个元素的数组。这对性能产生影响:当然,数组越大,性能就会下降。在我使用 150k id 进行的简单测试中,我得到了 800 毫秒的执行时间。但是,一切都取决于 CPU、内存、负载、数据大小、数据映射等。最好是让您实际测试一下。
2016 年 12 月更新:这个答案适用于 2014 年底存在的 Elasticsearch 版本,即 1.x 分支。当时最新可用的是 1.4.x。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)