17

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

4

1 回答 1

31

文档中,

“[通配符查询] 匹配具有与通配符表达式匹配的字段的文档(未分析) ”。

由于未分析搜索词,因此您基本上需要在生成搜索查询之前自己运行分析。在这种情况下,这只意味着您的搜索词需要小写。或者,您可以使用query_string

{
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "query": "name:Rae*"
          }
        }
      ]
    }
  }
}
于 2013-06-24T16:39:52.207 回答