elasticsearch 忽略大小寫模糊搜索實現

在es查詢時不區分大小寫,可讓查詢更方便,具體設置以下:app

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

設置完mappings後,在搜索的時候搜索的 userName 轉成小寫進行搜索spa

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

這樣設置後就能夠了。code

相關文章
相關標籤/搜索