在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的源代码:
当请求进来时,有一个解析器数组的解析器.它所使用的只是一个ArrayList
.然后将其传递给Lucene,而Lucene又使用List.
这是Lucene TermsFilter类(第84行),它从List中的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
)是2147483639
.所以,这将是该阵列的理论最大尺寸.
我已经在我的ES实例中本地测试了150000个元素的数组.这就是性能影响:当然,阵列越大,性能就越差.在我使用150k ID的简单测试中,我得到了800毫秒的执行时间.但是,所有这些都取决于CPU,内存,负载,数据量,数据映射等等.最好的是你实际测试它.
更新于2016年12月:此答案适用于2014年底存在的Elasticsearch版本,即1.x分支.当时的最新版本是1.4.x.
是! 字段中的值的数量是可配置的.默认情况下,它限制为1024.您可以在elasticsearch.yml文件中配置它.
indices.query.bool.max_clause_count: 10000
注意:增加限制将导致高内存和CPU使用率.
有关详细信息,请参阅这些链接:
https://groups.google.com/forum/#!topic/elasticsearch/LqywKHKWbeI
https://github.com/elasticsearch/elasticsearch/issues/482
http://elasticsearch-users.115913.n3.nabble.com/index-query-bool-max-clause-count-Setting-and-TermsQueryParser-td3050751.html
http://elasticsearch-users.115913.n3.nabble.com/Query-string-length-limit-td4054066.html