elastic javaapi regex case insensitive

Viewed 458
GET /_search
{
  "query": {
    "regexp": {
      "user.id": {
        "value": "k.*y",
        "case_insensitive": true,
      }
    }
  }
}

what is java api equivalent for this example (above query) in elastic docs ? I can't find a way to add case_insensitive.

QueryBuilders.regexpQuery("user.id", "k.*y")
1 Answers

AFAIK there is no Querybuilder in Elasticsearch which supports case insensitive option, you need to Anlayze your field so that it creates a lowercase token and than you the match query which uses the same analyzer on the search term and lowercases the search term, that way you can achieve the case-insensitive search in Elasticsearch.

Note : Default analyzer standard uses the lowercases the tokens, otherwise you can use the lower case token filter in your analyzer and make it work.

EDIT: Looks like Elasticsearch recently added the support of caseInsensitive param and it was added as part of this PR which was merged on 25th Aug, 2020 and it looks like it supports ES versions greater than or equal to 7.10.

Related