2

I wrote a query for get all clients whose name start with c. I am getting the same results with the two following queries:

#Q1 Query String and * wildcard
GET /client/_search
{
  "query": {
    "query_string": {
      "default_field": "Name.keyword",
      "query": "c*"
    }
  }
}


#Q2 prefix query
GET /client/_search
{
    "query": {
        "prefix": {
            "Name.keyword": {
                "value": "c"
            }
        }
    }
}

I guess the string query is less efficient as it is explained here:

Be aware that wildcard queries can use an enormous amount of memory and perform very badly — just think how many terms need to be queried to match the query string " a* b* c* ".

But could somebody tell me which one would be the best and more efficient for my approach?

Thanks.

César
  • 143
  • 2
  • 14
  • You can check `index_prefixes` https://www.elastic.co/guide/en/elasticsearch/reference/current/faster-prefix-queries.html – alpert Jan 17 '20 at 15:12

0 Answers0