其他分享
首页 > 其他分享> > elasticsearch 忽略大小写模糊搜索实现(转)

elasticsearch 忽略大小写模糊搜索实现(转)

作者:互联网

在es查询时不区分大小写,可以让查询更方便,具体设置如下:

{
    "settings": {
        "analysis": {
            "analyzer": {
                "caseSensitive": {
                    "filter": "lowercase",
                    "type": "custom",
                    "tokenizer": "keyword"
                }
            }
        }
    },
    "mappings": {
        "personInfo": {
            "properties": {
                "userName": {
                    "type": "string",
                    "analyzer": "caseSensitive",
                    "search_analyzer": "caseSensitive"
                }
            }
        }
    }
}

  

设置完mappings后,在搜索的时候搜索的 userName 转成小写进行搜索

{
  "query":{
        "wildcard" : {
            "userName": "*zhangsan*"
        }
  }
}

  

 

标签:userName,搜索,mappings,analyzer,忽略,caseSensitive,大小写,elasticsearch,type
来源: https://www.cnblogs.com/sandea/p/10382174.html