Skip to content

[Feature Request] Skipping unnecessary document traversal When using dynamic pruning in cardinality aggregation #18381

Description

@kkewwei

Is your feature request related to a problem? Please describe

In #13821, we introduced "Support Dynamic Pruning in Cardinality Aggregation", once we collect one document, we will not collect the values of this document anymore in cardinality aggregation. However, the ScoreMode is set to COMPLETE or COMPLETE_NO_SCORES by cardinality aggregation, we have to continue collecting the remaining documents, even if we have already collected the number of documents specified by the totalHitsThreshold.

We can reproduce by the dsl:

POST logs1/_search
{
   "query": {
      "range": {
         "age": {
            "from": 1
         }
      }
   },
   "aggs": {
      "terms1": {
         "cardinality": {
            "field": "name"
         }
      }
   }
}

Describe the solution you'd like

Once all distinct values have been collected, the cardinality aggregation becomes redundant, and there is no need to traversal the rest of documents. A potential solution is to dynamically adjust the ScoreMode from COMPLETE_NO_SCORES to TOP_SCORES in cardinality aggregation.

Related component

Search:Aggregations

Describe alternatives you've considered

No response

Additional context

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status
🆕 New

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions