沒有用到elasticsearch的全文搜索特性,反而它的分詞給我帶來不少困擾。好比一個字段是html
Wang Dai
我想用正則表達式去匹配,卻只能使用單個詞的匹配好比W.*g
或者D.*i
而不能使用整個句子的匹配W.*i
正則表達式
這個問題能夠參考http://elasticsearch-users.115913.n3.nabble.com/Disabling-default-analyzer-td2932819.html
如下是我本身的記錄app
PUT /<index_name>/_mapping { <type_name>: { properties: { <column_name>: {type: string, index: not_analyzed} } } }
PUT /<index_name> { analysis: { analyzer: { default: { type: keyword } } } }
或在elasticsearch.yml
中加上elasticsearch
index: analysis: analyzer: default: type: keword
但這種方法略坑,由於它仍是能按詞搜,不過按句子搜也是能夠了code
這種沒用過,跟加not_analyzed
是同樣的,不過是把加這個參數設置成默認行爲htm