zoukankan      html  css  js  c++  java
  • elasticsearch查询时不区分大小写

    Elastic 默认是区分大小写查询的,比如:

    {
      "foo": "BÀR"
    }

    查询的时候 通过“bar”是查询不到的,需要在

    "settings": {
    
        "analysis": { 
          "normalizer": { 
            "my_normalizer": { 
              "type": "custom", 
              "filter": ["lowercase", "asciifolding"] 
            } 
          } 
        } 
      },   
       "mappings": { 
        "type": { 
          "properties": { 
            "foo": { 
              "type": "keyword", 
              "normalizer": "my_normalizer" 
            } 
          } 
        } 
      } 

    案例:

    PUT /products
    {
      "settings": {     
        "analysis": { 
          "normalizer": { 
            "my_normalizer": { 
              "type": "custom", 
              "filter": ["lowercase", "asciifolding"] 
            } 
          } 
        } 
      }
    }
    
    POST /products/doc/_mapping
    {
      "_source": {"enabled": true},
      "dynamic": true,
      "properties" : {
        "id" : {"type" : "text","fields": {"raw": {"type": "keyword","ignore_above": 256}}},
        "hash" : {"type" : "text","fields": {"raw": {"type": "keyword","ignore_above": 256}}},
        "name" : {"type" : "keyword","doc_values":true,"normalizer": "my_normalizer"},
        "type" : {"type" : "keyword","doc_values":true},
        "fileids": {"type": "text","fields": {"raw": {"type": "keyword","ignore_above": 256}}},
        "createTime": {"type": "date"},
        "updateTime": {"type": "date"},
        "info" : {
          "properties":{              
                "id":{ "type":"text","fields": {"raw": {"type": "keyword","ignore_above": 256}}},
                "label":{"type":"keyword","doc_values":true,"normalizer": "my_normalizer"},
                "format":{ "type":"keyword","doc_values":true,"normalizer": "my_normalizer"},
                "value" : {"type" : "text","fields": {"raw": {"type": "keyword","ignore_above": 256}}}
         }
       }
     } 
    }
    View Code

    这样就可以解决大小写的问题。

    ES 6.0 官网资料:https://www.elastic.co/guide/en/elasticsearch/reference/6.0/normalizer.html

  • 相关阅读:
    05-3. 六度空间 (PAT)
    05-2. Saving James Bond
    05-1. List Components (PAT)
    04-3. Huffman Codes (PAT)
    04-2. File Transfer (PAT)
    04-1. Root of AVL Tree (PAT)
    03-3. Tree Traversals Again (PAT)
    03-2. List Leaves (PAT)
    03-1. 二分法求多项式单根(PAT)
    CDH Namenode自动切换(active-standby)
  • 原文地址:https://www.cnblogs.com/chong-zuo3322/p/14036861.html
Copyright © 2011-2022 走看看