Count values in terms based on the starting character

Hello,
I have an index seach-2019-08* and it has term site. I want to count the terms based on the starting character of the site.

GET search-2019-08*/_count
{ "query": { "bool": {
"must": [
{
"term": {
"site": "a*"
} } ] } }}

I'm looking for the count of documents with site starts with a. but, it always return 0. But, I know, there is some data like that

You can't use wildcards in a term query. What you're doing here is search for documents that contain the exact two characters a and *.

If you want to use wildcards, you have to use the wildcard query:

GET search-2019-08*/_count
{
  "query": {
    "wildcard": {
      "site": {
        "value": "a*"
      }
    }
  }
}

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