How to implement case sensitive search in elasticsearch?

I have a field in my indexed documents where I need to search with case sensitive. I use a match query to get results. An example of my data document:

{
"name" : "binoy",
"age" : 26,
"country": "India"
}

Now when I give the following request:

{
"query" : {
"match" : {
"name" : "Binoy"
}
}
}

This gives me a match for Bina against Bina. I want the search to be case sensitive. Apparently, apparently, elasticsearch seems to come with an insensitive case. How to make search case sensitive in elastics search?

+4
source share
4 answers

In the display, you can define the field as not_analyzed.

curl -X PUT "http://localhost:9200/sample" -d '{
  "index": {
    "number_of_shards": 1,
    "number_of_replicas": 1
  }
}'

echo
curl -X PUT "http://localhost:9200/sample/data/_mapping" -d '{
  "data": {
    "properties": {
      "name": {
        "type": "string",
        "index": "not_analyzed"
      }
    }
  }
}'

, , , .

+3

:

PUT /whatever
{
  "settings": {
    "analysis": {
      "analyzer": {
        "mine": {
          "type": "custom",
          "tokenizer": "standard"
        }
      }
    }
  },
  "mappings": {
    "type": {
      "properties": {
        "name": {
          "type": "string",
          "analyzer": "mine"
        }
      }
    }
  }
}

lowercase .

+3

, name. - , elasticsearch ( ) , , . "" ""

, lowercase name. ,

"analyzer": {
                "casesensitive_text": {
                    "type":         "custom",
                    "tokenizer":    "standard",
                    "filter": ["stop", "porter_stem" ]
                }
            }

name,

"name": {
    "type": "string", 
    "analyzer": "casesensitive_text"
}

name.

: , , . , .

+3

, ElasticSearch 5.6:

{
  "template": "logstash-*",
  "settings": {
     "analysis" : {
         "analyzer" : {
             "case_sensitive" : {
                 "type" : "custom",
                 "tokenizer":    "standard",
                 "filter": ["stop", "porter_stem" ]                    
             }
         }
     },        
     "number_of_shards": 5,
     "number_of_replicas": 1      
  },      
  "mappings": {
   "fluentd": {
     "properties": {
       "message": {
         "type": "text",
         "fields": {
           "case_sensitive": { 
             "type": "text",
             "analyzer": "case_sensitive"
           }
         }          
       }
     }
   }
  }
}

, FluentD logstash-*. , message, . / message message.case_sensitive.

0

Source: https://habr.com/ru/post/1589357/


All Articles