Case insensitivity does not work

走远了吗. 提交于 2019-11-30 01:06:14

问题


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


回答1:


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*"
          }
        }
      ]
    }
  }
}


来源:https://stackoverflow.com/questions/17266830/case-insensitivity-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!