使用 ES (elasticsearch) 搜索中文


1、创建索引
curl -XPUT http://172.16.125.139:9200/ques
2、创建索引类型
curl -XPOST http://172.16.125.139:9200/ques/common/_mapping -H 'Content-Type:application/json' -d '{"properties":{"question":{"type":"text","analyzer":"ik_max_word","search_analyzer":"ik_max_word","similarity":"BM25"},"answer":{"type":"text","analyzer":"ik_max_word","search_analyzer":"ik_max_word","similarity":"BM25"}}}'
3、push 数据
curl -XPOST http://172.16.125.139:9200/ques/common/1 -H 'Content-Type:application/json' -d '{"question":"xx", "answer":"xx"}'
curl -XPOST http://172.16.125.139:9200/ques/common/2 -H 'Content-Type:application/json' -d '{"question":"xx", "answer":"xx"}'
4、搜索
curl -XPOST http://172.16.125.139:9200/ques/common/_search -H 'Content-Type:application/json' -d '{"query":{"match": {"question":"xxx"}}}’

 

备注:

1、该操作是在 es 支持 ik 分词的基础上进行的,可以参考官网https://github.com/medcl/elasticsearch-analysis-ik

2、push、search数据的时候数据都是使用 xx 代替的,实际使用时替换成真是数据即可;

2、这里的相似度使用的是 BM25,也可以替换为 TFIDF

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM