首页 > 其他 > 详细

使用 ES (elasticsearch) 搜索中文

时间:2018-06-29 18:15:32      阅读:206      评论:0      收藏:0      [点我收藏+]

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

 

使用 ES (elasticsearch) 搜索中文

原文:https://www.cnblogs.com/shanguanghui/p/9244789.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!