不敏感的情况不起作用 [英] Case insensitivity does not work

查看:99
本文介绍了不敏感的情况不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么我的搜索区分大小写。我读过的一切都说ES默认是不敏感的。我有映射指定索引和搜索的标准分析器,但似乎有些东西仍然区分大小写 - 即通配符:

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

这样做失败,但是rae *按照需要工作。我需要使用通配符进行'开始'类型搜索(我推测)。



我正在使用.Net应用程序中的NEST,当我指定分析器时创建索引:

  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()));

在这种情况下,它使用简单的分析器,但标准的分析器具有相同的结果。



映射如下所示:

  name:{
type:字符串
分析器:简单
存储:是
}

任何人有什么想法这里有什么问题?



谢谢

解决方案

文档


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


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

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


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

解决方案

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

这篇关于不敏感的情况不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆