簡體   English   中英

Elasticsearch 6.1.2中不區分大小寫的搜索

[英]Case insensitive searching in elasticsearch 6.1.2

我正在嘗試搜索以下情況

我想搜索一個以特定單詞結尾的名稱。 例如:

名稱:小組測試

名稱:小組測試

名稱:組測試組織

這是我的通配符查詢

"bool" : {
    "must" : [
            {
            "wildcard" : {
                "name.keyword"" : {
                    "wildcard" : "*test",
                    "boost" : 1.0
                }
            }
        }
    ]
}

返回區分大小寫搜索的“小組測試”

但是對於大小寫不敏感的搜索,我需要同時獲得“組測試”和“組測試”。

我的映射如下:

 "name":{
            "type":"text",
            "fielddata":true
            "fields":{
                "keyword":{
                            "type":"keyword"
                        }
                }
         }

誰能幫我找出Elasticsearch Java API或其他任何搜索方式的查詢。

彈性搜索版本6.1.2

任何幫助都非常感謝。

不幸的是,沒有通過ES配置執行此操作的直接方法,因為keyword類型不具有analyzer屬性,但是我找到了一種解決方法。 請看一下這個解決方案

PUT test
{  
  "settings": {
    "analysis": {
      "analyzer": {
        "folding": {
          "tokenizer": "standard",
          "filter":  [ "lowercase", "asciifolding" ]
        }
      },
      "normalizer": {
        "lowerasciinormalizer": {
          "type": "custom",
          "filter":  [ "lowercase", "asciifolding" ]
        }
      }
    }
  },
  "mappings": {
    "_default_": {
      "dynamic_templates": [
        {
          "string_as_keyword": {
            "match_mapping_type": "string",
            "match":   "*_k",
            "mapping": {
              "type": "keyword",
              "normalizer": "lowerasciinormalizer"                              
            }
          }
        }
      ]
    }
  }
}

PUT test/1/123
{
  "str_k" : "string âgáÈÒU is cool"
}

GET test/_search
{
  "query": {
    "wildcard": {
      "str_k": "*agaeou*"
    }
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM