Unique values - Terms aggregation or Wildcard query

What's the best way to get all the unique terms for a field? Can use either terms aggregation or a wild card query (and then reduce it to unique terms at the application side)?

{
    "query": {
        "wildcard" : { "text" : "**" }
    }
}

or

{
    "aggs" : {
        "genres" : {
            "terms" : { "field" : "text" }
        }
    }
}

Terms aggregation lets elastic-search reduce the terms to unique values using column store approach (in a distributed manner) and thereby reduce the response payload. But is it going to put too much load on elasticsearch?
Wildcard i believe relies on the inverted indexes to do this.

I'm aware of the shard size aspect of the terms aggregation. Other than that, is one internally optimized than the other or not? What's the execution plan for each?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.