Elasticsearch Map对not_analyzed文档不敏感

use*_*474 25 elasticsearch

我有一个带有以下映射的类型

PUT /testindex
{
    "mappings" : {
        "products" : {
            "properties" : {
                "category_name" : {
                    "type" : "string",
                    "index" : "not_analyzed" 
                }
            }
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

我想搜索一个确切的单词.这就是为什么我把它设置为not_analyzed.但问题是我想用小写或大写搜索[不区分大小写].

我搜索它并找到了一种设置不区分大小写的方法.

curl -XPOST localhost:9200/testindex -d '{
  "mappings" : {
    "products" : {
      "properties" : {        
        "category_name":{"type": "string", "index": "analyzed", "analyzer":"lowercase_keyword"}
      }
    }
  }
}'
Run Code Online (Sandbox Code Playgroud)

有没有办法将这两个映射到同一个字段.

谢谢..

Joh*_*one 38

我认为这个例子符合您的需求:

$ curl -XPUT localhost:9200/testindex/ -d '
{
  "settings":{
     "index":{
        "analysis":{
           "analyzer":{
              "analyzer_keyword":{
                 "tokenizer":"keyword",
                 "filter":"lowercase"
              }
           }
        }
     }
  },
  "mappings":{
     "test":{
        "properties":{
           "title":{
              "analyzer":"analyzer_keyword",
              "type":"string"
           }
        }
     }
  }
}'
Run Code Online (Sandbox Code Playgroud)

取自此处:如何在elasticsearch中设置tokenizer

它在字符串字段上使用关键字tokenizer和小写过滤器,我相信它可以满足您的需求.

  • 上面的答案对于op想要的是正确的.它的行为类似于`not_analyzed`字段,除了它不区分大小写. (2认同)

小智 6

如果您只想要不区分大小写的查询,请考虑在开展业务之前将数据和查询更改为大写/小写.

这意味着您只保留您的字段not_analyzed并仅在其中一个案例中输入数据/查询.


Ale*_*lex 3

keyword只需使用分词器和分词过滤器创建自定义分析器即可lowercase


归档时间:

查看次数:

23599 次

最近记录:

9 年,5 月 前