使用 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