Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultiIndex search with filters aggregation and range filter may return IndexOutOfBoundsException exception #32834

Closed
voidlps opened this issue Aug 14, 2018 · 2 comments
Assignees

Comments

@voidlps
Copy link

voidlps commented Aug 14, 2018

Elasticsearch version (bin/elasticsearch --version): 6.2.4

Plugins installed: []

JVM version (java -version):

OS version (uname -a if on a Unix-like system): docker image

Description of the problem including expected versus actual behavior:
If range query is using non-existing field, other_bucket will never be generated in result.
And the equivalent query_string seems working without problem.
Even worse, when using multi-index search, it may lead to Array IndexOutOfBoundsException exception

Steps to reproduce:

PUT test1/_doc/1
{
  "n": 15
}

PUT test2/_doc/1
{
  "m": 15
}

POST test1/_search
{
  "size": 0,
  "aggs": {
    "test_other_bucket": {
      "filters": {
        "other_bucket": true,
        "filters": {
          "all": {
            "match_all": {}
          },
          "query_string": {
            "query_string": {
              "query": "m:[10 TO 20]"
            }
          },
          "use_range": {
            "range": {
              "m": {
                "gte": 10,
                "lte": 20
              }
            }
          }
        }
      }
    }
  }
}

POST test1/_search
{
  "size": 0,
  "aggs": {
    "test_other_bucket": {
      "filters": {
        "other_bucket": true,
        "filters": {
          "all": {
            "match_all": {}
          },
          "query_string": {
            "query_string": {
              "query": "m:[10 TO 20]"
            }
          }
        }
      }
    }
  }
}

POST test2/_search
{
  "size": 0,
  "aggs": {
    "test_other_bucket": {
      "filters": {
        "other_bucket": true,
        "filters": {
          "all": {
            "match_all": {}
          },
          "query_string": {
            "query_string": {
              "query": "m:[10 TO 20]"
            }
          },
          "use_range": {
            "range": {
              "m": {
                "gte": 10,
                "lte": 20
              }
            }
          }
        }
      }
    }
  }
}

POST test*/_search
{
  "size": 0,
  "aggs": {
    "test_other_bucket": {
      "filters": {
        "other_bucket": true,
        "filters": {
          "all": {
            "match_all": {}
          },
          "query_string": {
            "query_string": {
              "query": "m:[10 TO 20]"
            }
          },
          "use_range": {
            "range": {
              "m": {
                "gte": 10,
                "lte": 20
              }
            }
          }
        }
      }
    }
  }
}

Provide logs (if relevant):

[2018-08-14T07:59:14,013][WARN ][r.suppressed             ] path: /test*/_search, params: {index=test*}
org.elasticsearch.action.search.SearchPhaseExecutionException: 
	at org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseFailure(AbstractSearchAsyncAction.java:274) [elasticsearch-6.2.4.jar:6.2.4]
	at org.elasticsearch.action.search.FetchSearchPhase$1.onFailure(FetchSearchPhase.java:92) [elasticsearch-6.2.4.jar:6.2.4]
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.onFailure(ThreadContext.java:657) [elasticsearch-6.2.4.jar:6.2.4]
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:39) [elasticsearch-6.2.4.jar:6.2.4]
	at org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:41) [elasticsearch-6.2.4.jar:6.2.4]
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-6.2.4.jar:6.2.4]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_161]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_161]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_161]
Caused by: java.lang.IndexOutOfBoundsException: Index: 3, Size: 3
	at java.util.ArrayList.rangeCheck(ArrayList.java:657) ~[?:1.8.0_161]
	at java.util.ArrayList.get(ArrayList.java:433) ~[?:1.8.0_161]
	at org.elasticsearch.search.aggregations.bucket.filter.InternalFilters.doReduce(InternalFilters.java:221) ~[elasticsearch-6.2.4.jar:6.2.4]
	at org.elasticsearch.search.aggregations.InternalAggregation.reduce(InternalAggregation.java:136) ~[elasticsearch-6.2.4.jar:6.2.4]
	at org.elasticsearch.search.aggregations.InternalAggregations.reduce(InternalAggregations.java:77) ~[elasticsearch-6.2.4.jar:6.2.4]
	at org.elasticsearch.action.search.SearchPhaseController.reduceAggs(SearchPhaseController.java:527) ~[elasticsearch-6.2.4.jar:6.2.4]
	at org.elasticsearch.action.search.SearchPhaseController.reducedQueryPhase(SearchPhaseController.java:504) ~[elasticsearch-6.2.4.jar:6.2.4]
	at org.elasticsearch.action.search.SearchPhaseController.reducedQueryPhase(SearchPhaseController.java:421) ~[elasticsearch-6.2.4.jar:6.2.4]
	at org.elasticsearch.action.search.SearchPhaseController$1.reduce(SearchPhaseController.java:740) ~[elasticsearch-6.2.4.jar:6.2.4]
	at org.elasticsearch.action.search.FetchSearchPhase.innerRun(FetchSearchPhase.java:102) ~[elasticsearch-6.2.4.jar:6.2.4]
	at org.elasticsearch.action.search.FetchSearchPhase.access$000(FetchSearchPhase.java:45) ~[elasticsearch-6.2.4.jar:6.2.4]
	at org.elasticsearch.action.search.FetchSearchPhase$1.doRun(FetchSearchPhase.java:87) ~[elasticsearch-6.2.4.jar:6.2.4]
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:672) ~[elasticsearch-6.2.4.jar:6.2.4]
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) ~[elasticsearch-6.2.4.jar:6.2.4]
	... 5 more
@voidlps voidlps changed the title MultiIndex search with filters aggregation and range filter, return IndexOutOfBoundsException exception if some index doesn't have the field at all MultiIndex search with filters aggregation and range filter may return IndexOutOfBoundsException exception Aug 14, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

@jtibshirani
Copy link
Contributor

Thank you @voidlps for the detailed bug report -- I've opened a PR to address the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants