我可以在ids过滤器或一般查询子句中指定的值数量的最大限制?

Pho*_*nix 29 elasticsearch

在elasticsearch中,指定可以执行匹配的值的数量的最大限制是多少?我在某处读到它是1024,但也是可配置的.真的吗?它如何影响性能?

curl -XPOST 'localhost:9200/my_index/_search?pretty' -d '{
  "query": {
    "filtered": {
      "filter": {
        "not": {
          "ids": {
            "type": "my_type",
            "values": ["1", "2", "3"]
}}}}}}'
Run Code Online (Sandbox Code Playgroud)

我可以在此数组中指定多少个值?限制是多少?如果可配置,对增加限制的性能影响是什么?

And*_*fan 34

我不认为Elaticsearch或Lucene明确规定了任何限制.但是,您可能遇到的限制是JDK设置的限制.

为了证明我上面的陈述,我查看了Elasticsearch的源代码:

/**
 * 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;
}
Run Code Online (Sandbox Code Playgroud)

那个数字(Integer.MAX_VALUE - 8)是2147483639.所以,这将是该阵列的理论最大尺寸.

我已经在我的ES实例中本地测试了150000个元素的数组.这就是性能影响:当然,阵列越大,性能就越差.在我使用150k ID的简单测试中,我得到了800毫秒的执行时间.但是,所有这些都取决于CPU,内存,负载,数据量,数据映射等等.最好的是你实际测试它.

更新于2016年12月:此答案适用于2014年底存在的Elasticsearch版本,即1.x分支.当时的最新版本是1.4.x.

  • @Cheruvian`ids`与`maxClauseCount`无关(它与`bool`查询/过滤器中的布尔语句有关).`ids`不会被重写为一堆`bool`语句.最有可能的是,您的问题来自查询的其他部分,与"ids"无关.您的downvote和评论不适用于此帖子. (3认同)
  • @Cheruvian我也用大块测试它,这对1,200,000个术语(每个应该有1000个术语)都很好.在此限制之后,我得到了all_shards_failed异常 (3认同)
  • 这是不正确的,默认情况下限制为1024。 (2认同)

Bla*_*POP 12

是! 字段中的值的数量是可配置的.默认情况下,它限制为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

  • 你说的是别的东西:它是关于查询或过滤器中可以有多少个布尔子句,简单地说明Elasticsearch在单个查询中允许的"MUST","SHOULD"或"MUST_NOT"语句的数量. (12认同)
  • 这个答案是关于布尔子句的最大数量,而不是单个子句的值的数组中的最大元素数量。 (2认同)

Ami*_*adi 7

ES 7.0中将引入对术语查询中术语数量的索引级别限制。

设置为 index.max_terms_count,默认值为 65536。