博客
关于我
Elasticsearch 多种搜索方式
阅读量:257 次
发布时间:2019-03-01

本文共 1207 字,大约阅读时间需要 4 分钟。

1、Query String Search

通过URL查询参数构建简单的搜索语句,适用于基础的文本搜索。

示例:GET /ecommerce/product/_search?q=name:yagao&sort=price:desc

效果:返回包含"yagao"的商品名称,并按价格降序排列。

响应示例:

took: 288ms

timed_out: false

_shards: { total: 5, successful: 5, skipped: 0, failed: 0 }

hits: { total: 3, max_score: 1, hits: [ { _id: "2", _score: 1, _source: { name: "jiajieshiyagao", ... } } ] }

2、Query DSL

使用JSON格式构建更复杂的查询语句,支持多种高级搜索功能。

基本结构:

GET /ecommerce/product/_search{ "query": { match_all: {} }, "sort": [ { price: "desc" } ] }

高级用法:

GET /ecommerce/product/_search{ "query": { bool: { must: { match: { name: "yagao" } }, filter: { range: { price: { gt: 25 } } } }, "sort": [ { price: "desc" } ] }

3、Query Filter

对结果进行过滤,满足特定条件的查询。

示例:

GET /ecommerce/product/_search{ "query": { bool: { must: { match: { name: "yagao" } }, filter: { range: { price: { gt: 25 } } } }, "sort": [ { price: "desc" } ] }

4、Full-Text Search

支持全文检索,通过倒排索引快速定位相关内容。

示例:

GET /ecommerce/product/_search{ "query": { match: { producer: "yagao producer" } } }

5、Phrase Search

精确匹配短语,确保搜索词完整出现。

与全文检索的区别:

全文检索会拆分查询词,匹配任意字符;短语搜索要求完整匹配。

6、Highlight Search

在搜索结果中高亮显示匹配的关键词或短语。

示例:

GET /ecommerce/product/_search{ "query": { match: { name: "yagao" } }, "highlight": [ "name" ] }

转载地址:http://mvft.baihongyu.com/

你可能感兴趣的文章
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>
NO.23 ZenTaoPHP目录结构
查看>>
NO32 网络层次及OSI7层模型--TCP三次握手四次断开--子网划分
查看>>
NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
查看>>
Node JS: < 一> 初识Node JS
查看>>
Node-RED中使用JSON数据建立web网站
查看>>
Node-RED中使用json节点解析JSON数据
查看>>
Node-RED中使用node-red-browser-utils节点实现选择Windows操作系统中的文件并实现图片预览
查看>>
Node-RED中使用Notification元件显示警告讯息框(温度过高提示)
查看>>
Node-RED中实现HTML表单提交和获取提交的内容
查看>>
Node.js 函数是什么样的?
查看>>
Node.js 实现类似于.php,.jsp的服务器页面技术,自动路由
查看>>
node.js 怎么新建一个站点端口
查看>>
Node.js 文件系统的各种用法和常见场景
查看>>
node.js 配置首页打开页面
查看>>
node.js+react写的一个登录注册 demo测试
查看>>
Node.js中环境变量process.env详解
查看>>