Pratz
Pratz

Reputation: 359

Elasticsearch wildcard query not honoring the analyzer of the field

I have a field named "tag" which is analyzed(default behavior) in elasticsearch. The "tag" field can have a single word or a comma separated string to store multiple tags. For eg. "Festive, Fast, Feast". Now for example if a tag is "Festive", before indexing I am converting it to small case(to ignore case sensitivity) and indexing it as "festive".

Now if I search using a match query with all caps letters as mentioned below I get results fine(as expected).

{
    "query": {
        "match": {
           "tag": "FESTIVE"
        }
    }
}

But if I do a wildcard query as mentioned below I don't get results :(

{
    "query": {
        "wildcard": {
           "tag": {
              "value": "F*"
           }
        }
    }
}

If I change the value field in wildcard search to "f*" instead of "F*" then I get results.

Does anyone have any clue why is wildcard query behaving case sensitive?

Upvotes: 3

Views: 6852

Answers (1)

ChintanShah25
ChintanShah25

Reputation: 12672

Wildcard queries, fall under term level queries and hence not analyzed. From the Docs

Matches documents that have fields matching a wildcard expression (not analyzed)

You will get expected results with query string query, it will lowercase the terms because by default as lowercase_expanded_terms is true. Try this

GET your_index/_search
{
  "query": {
    "query_string": {
      "default_field": "tag",
      "query": "F*"
    }
  }
}

Hope this helps!

Upvotes: 6

Related Questions