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

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-23
  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
  • 2021-12-30
猜你喜欢
  • 2022-12-23
  • 2021-07-10
  • 2021-05-24
  • 2021-12-23
  • 2021-08-18
  • 2022-12-23
  • 2021-09-19
相关资源
相似解决方案