Smail_
2017-05-05 21:06:18
Elasticsearch5.3.2 + elasticsearch-analysis-ansj + elasticsearch-analysis-pinyin + Ngram整合实例
这篇文章适合给用es做中文搜索引擎的同行!
127.0.0.1:9200/<your-index-name> { "index": { "analysis": { "tokenizer": { "ansj_pinyin_tokenizer": { "type": "dic_ansj", "filter": ["pinyin_filter", "ng_filter"] } }, "filter": { "pinyin_filter": { "type": "pinyin", "first_letter": "prefix", "padding_char": " " }, "ng_filter": { "type": "ngram", "min_gram": 1, "max_gram": 5, "token_chars": [ "letter", "digit" ] } }, "analyzer": { "ansj_pinyin_analyzer": { "tokenizer": "ansj_pinyin_tokenizer" } } } } }
127.0.0.1:9200/<your-index-name>/_mapping/<your-type-name> { "properties": { "table": { "type": "text" }, "title": { "type": "text", "term_vector": "with_positions_offsets", "analyzer": "dic_ansj", "search_analyzer": "query_ansj", "fields": { "pinyin": { "type": "text", "analyzer": "ansj_pinyin_analyzer" } } }, "digest": { "type": "text", "term_vector": "with_positions_offsets", "analyzer": "dic_ansj", "search_analyzer": "query_ansj", "fields": { "pinyin": { "type": "text", "analyzer": "ansj_pinyin_analyzer" } } }, "category_id": { "type": "long" }, "source_id": { "type": "long" }, "pub_time": { "type": "date", "format": "yyyy-MM-dd HH:mm:ss" }, "copyright": { "type": "long" }, "level": { "type": "long" }, "thumb_up_num": { "type": "long" }, "browse_num": { "type": "long" }, "follow_num": { "type": "long" }, "comment_num": { "type": "long" }, "recommend": { "type": "long" }, "stick": { "type": "long" }, "status": { "type": "long" }, "create_time": { "type": "date", "format": "yyyy-MM-dd HH:mm:ss" }, "update_time": { "type": "date", "format": "yyyy-MM-dd HH:mm:ss" } } }
导入数据(增加数据索引)!
搜索!
黄xiaoc,黄xc,黄小厨......
Perfact!
躺坑:
1.Validation Failed: 1: mapping type is missing;
2.Root mapping definition has unsupported parameters
3.The [string] type is removed in 5.0 and automatic upgrade failed because parameters [index_analyzer] are not supported for automatic upgrades. You should now use either a [text] or [keyword] field instead for field [pinyin]
A:解决方案reson已经告诉你了,string -> text
4.analyzer on field [pinyin] must be set when search_analyzer is set
remove
"index_analyzer": "pinyin_analyzer", "search_analyzer": "query_ansj"
add
"analyzer": "index_ansj"
5.No handler for type [int] declared on field [category_id]
int -> long or integer
一次一次的测试配置是否有效......
GAME OVER !
上面是配置好了的!直接拿去用吧!
评论
最近浏览
AlanLi LV19
2022年4月14日
txf1994
2020年2月13日
暂无贡献等级
安安an LV17
2019年7月23日
lxwlf3000
2018年11月23日
暂无贡献等级
zhoushihui27 LV5
2018年3月26日
贾大神 LV5
2017年11月7日
zhaodaren LV7
2017年10月13日
清风5动 LV8
2017年9月20日
15123386030 LV7
2017年9月18日
18202838208 LV14
2017年9月3日