Case insensitivity does not work

Jonesie picture Jonesie · Jun 24, 2013 · Viewed 18.7k times · Source

I cant figure out why my searches are case sensitive. Everything I've read says that ES is insensitive by default. I have mappings that specify the standard analyzer for indexing and search but it seems like some things are still case sensitive - ie, wildcard:

"query": {
"bool": {
  "must": [
    {
      "wildcard": {
        "name": {
          "value": "Rae*"
        }
      }
    }
  ]
}

This fails but "rae*" works as wanted. I need to use wildcard for 'starts-with' type searches (I presume).

I'm using NEST from a .Net app and am specifying the analyzers when I create the index thus:

  var settings = new IndexSettings();
  settings.NumberOfReplicas = _configuration.Replicas;
  settings.NumberOfShards = _configuration.Shards;
  settings.Add("index.refresh_interval", "10s");
  settings.Analysis.Analyzers.Add(new KeyValuePair<string, AnalyzerBase>("keyword", new KeywordAnalyzer()));
  settings.Analysis.Analyzers.Add(new KeyValuePair<string, AnalyzerBase>("simple", new SimpleAnalyzer()));

In this case it's using the simple analyzer but the standard one has the same result.

The mapping looks like this:

name: {
    type: string
    analyzer: simple
    store: yes
}

Anyone got any ideas whats wrong here?

Thanks

Answer

Matthew Boynes picture Matthew Boynes · Jun 24, 2013

From the documentation,

"[The wildcard query] matches documents that have fields matching a wildcard expression (not analyzed)".

Because the search term is not analyzed, you'll essentially need to run the analysis yourself before generating the search query. In this case, this just means that your search term needs to be lowercase. Alternatively, you could use query_string:

{
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "query": "name:Rae*"
          }
        }
      ]
    }
  }
}