当前位置: 首页 > news >正文

Elasticsearch 自动补全 completion type

Elasticsearch 自带一种自动补全类型 completion 这种类型不在mapping文档里面有点坑。

先直接上例子。

建立 index,把我们要自动补全的字段设置为 completion 类型
或者直接设置为子类型

PUT /blogs_completion/
{"mappings": {"tech": {"properties": {"body": {"type": "completion"}}}}
}// 设置为子类型
PUT /blogs_completion/
{"mappings": {"properties": {"body": {"type": "text","fields": {"suggest":{"type":"completion"},"keyword":{"type":"keyword"}}}}}
}//填充测试用例inter开头文本,和inter 的变形单词inber等
POST _bulk/?refresh=true
{ "index" : { "_index" : "blogs_completion", "_type" : "tech" } }
{ "body": "interface test1"}
{ "index" : { "_index" : "blogs_completion", "_type" : "tech" } }
{ "body": "interf test2"}
{ "index" : { "_index" : "blogs_completion", "_type" : "tech" } }
{ "body": "inter test3"}
{ "index" : { "_index" : "blogs_completion", "_type" : "tech" } }
{ "body": "inber test"}
{ "index" : { "_index" : "blogs_completion", "_type" : "tech" } }
{ "body": "sinter test"}// 使用带模糊匹配的 completion suggester 查询POST blogs_completion/_search?pretty
{ "size": 0,"suggest": {"blog-suggest": {"prefix": "inter","completion": {"size":"5","field": "body","fuzzy" : {"fuzziness" : 2}}}}
}// 结果{"took" : 1,"timed_out" : false,"_shards" : {"total" : 5,"successful" : 5,"skipped" : 0,"failed" : 0},"hits" : {"total" : 0,"max_score" : 0.0,"hits" : [ ]},"suggest" : {"blog-suggest" : [{"text" : "inter","offset" : 0,"length" : 5,"options" : [{"text" : "inter test","_index" : "blogs_completion","_type" : "tech","_id" : "Fd_wOHABW8nrxgV2Ej6u","_score" : 3.0,"_source" : {"body" : "inter test"}},{"text" : "interf test","_index" : "blogs_completion","_type" : "tech","_id" : "FN_wOHABW8nrxgV2Ej6u","_score" : 3.0,"_source" : {"body" : "interf test"}},{"text" : "interface test","_index" : "blogs_completion","_type" : "tech","_id" : "E9_wOHABW8nrxgV2Ej6u","_score" : 3.0,"_source" : {"body" : "interface test"}},{"text" : "inber test","_index" : "blogs_completion","_type" : "tech","_id" : "HN__OHABW8nrxgV2lD4C","_score" : 2.0,"_source" : {"body" : "inber test"}}]}]}
}

概述:

Elasticsearch 自带 suggest query 的功能,作为自动补全和查询建议的工具,称为 suggester

分为四种:

  1. Term suggester
  2. Phrase Suggester
  3. Completion Suggester
  4. Context Suggester

Completion Suggester 已经可以满足我们一般的带模糊查询的前缀自动补全功能,
如果要做更复杂的自动补全,可以结合 term suggester 和 phrase suggester 和 completion,同时查询,合并结果,得到更复杂的结果

一般详细文档:

https://blog.csdn.net/wwd0501/article/details/80595201

官方详情查考

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html#context-suggester

http://www.lryc.cn/news/25340.html

相关文章:

  • GB28181协议实现源码Android源码
  • HNU工训中心: 三人表决器及八人抢答器实验报告
  • split()用法注意事项
  • centos7配置静态网络常见问题归纳
  • 产品经理修炼指南【01】
  • NCRE计算机等级考试Python真题(十一)
  • cglib代理解析
  • GFD563A101 3BHE046836R0101
  • SAP 采购定价过程字段解析
  • 一篇搞懂tcp,http,socket,socket连接池之间的关系
  • 【JavaSE】对象的比较
  • Leetcode DAY 49~50:买卖股票的最佳时机 1 2 3 4
  • Android Handler机制(二) Handler 实现原理
  • Elasticsearch教程(19) 详解mapping之keyword
  • LeetCode算法复杂度分析(时间复杂度空间复杂度)
  • Android OpenCV(七十三):吊打高斯模糊的StackBlur Android 实践
  • 4.排序算法之一:冒泡排序
  • python自学之《21天学通Python》(16)——第19章 用Pillow库处理图片
  • 发布依赖到maven仓库
  • Laravel-admin之自定义操作日志
  • 用Python做了一个法律查询小工具,非常好用
  • 工作篇:触摸屏原理介绍
  • Ep_操作系统面试题-操作系统的分类
  • iframe或document监听滚动事件不起作用
  • 基频估计算法简介
  • linux修改DNS 系统版本Kylin V10桌面版
  • 如何使用 AWS Lambda 运行 selenium
  • 认识Cesium旋转大小变量
  • 异响加持、吐槽声不断,小鹏G9难解困局
  • 【react】react18的学习