本文介绍了Elasticsearch Map 对 not_analyzed 文档不区分大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a type with following mapping

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

}

我想搜索一个确切的词.这就是我将其设置为 not_analyzed 的原因.但问题是我想用小写或大写[不区分大小写]来搜索.

I wanted to search for an exact word.Thats why i set this as not_analyzed.But the problem is i want to search that with lower case or upper case[case insensitive].

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

I searched for it and found a way to set case insensitive.

curl -XPOST localhost:9200/testindex -d '{
  "mappings" : {
    "products" : {
      "properties" : {        
        "category_name":{"type": "string", "index": "analyzed", "analyzer":"lowercase_keyword"}
      }
    }
  }
}'

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

Is there any way to do these two mappings to same field.?

谢谢..

推荐答案

我认为这个例子满足你的需求:

I think this example meets your needs:

$ 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"
           }
        }
     }
  }
}'

取自此处:如何在 elasticsearch 中设置标记器

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

it uses both the keyword tokenizer and the lowercase filter on a string field which I believe does what you want.

这篇关于Elasticsearch Map 对 not_analyzed 文档不区分大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 08:02