Xhark
Xhark

Reputation: 841

Elastic Search aggregation starting with

Is there a way to add a filter to a terms aggregation so I get just the ones starting with certain string?

I'm starting from here:

{
  "query": {
    "match_all": {}
  },
  "aggs": {
    "address": {
      "terms": {
        "field": "address"
      }
    }
  }
}

Upvotes: 0

Views: 549

Answers (1)

Val
Val

Reputation: 217554

Use the include or exclude parameters:

{
  "query": {
    "match_all": {}
  },
  "aggs": {
    "address": {
      "terms": {
        "field": "address",
        "include": "Main.*"     <-- add this
      }
    }
  }
}

Upvotes: 2

Related Questions