You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-issues@jackrabbit.apache.org by "Nuno Santos (Jira)" <ji...@apache.org> on 2022/08/16 09:16:00 UTC

[jira] [Created] (OAK-9899) Optimize in(x, y, z) constraints to use the terms ES query instead of a union of range queries

Nuno Santos created OAK-9899:
--------------------------------

             Summary: Optimize in(x, y, z) constraints to use the terms ES query instead of a union of range queries
                 Key: OAK-9899
                 URL: https://issues.apache.org/jira/browse/OAK-9899
             Project: Jackrabbit Oak
          Issue Type: Improvement
          Components: indexing
            Reporter: Nuno Santos


The Elastic plugin is converting the {{in(x, y, z)}} constraint of SQL2 queries to a series of ElasticSearch range queries, one for each element in the set. For instance this query:
{code:sql}
select [jcr:path] from [nt:base] where [propa] in('2', '3', '5', '7')" 
{code}
is implemented with the following ElasticSearch query:
{noformat}
"query": {
  "bool": {
    "filter": [{
      "bool": {
        "should": [
          {"range": {"propa": {"gte": "2","lte": "2"}}},
          {"range": {"propa": {"gte": "3","lte": "3"}}},
          {"range": {"propa": {"gte": "5","lte": "5"}}},
          {"range": {"propa": {"gte": "7","lte": "7"}}},              
        ]
      }
    }]
  }
}
{noformat}
The resulting ES query may become very large if the set in the {{in}} constraint is large, resulting in a large JSON request (which may be slow to generate, send and parse) and a potentially long execution time. In the worst case, the query can hit some size limits of ElasticSearch and fail.

The same {{in}} constraint can be expressed much more efficiently using the ElasticSearch {{terms}} query:
{noformat}
{
  "bool": {
    "filter": {
      "terms": {
        "propa": [2", "3", "5", "7"]
      }
    }
  }
}
{noformat}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)