博客
关于我
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/

你可能感兴趣的文章
NI笔试——大数加法
查看>>
NLP 基于kashgari和BERT实现中文命名实体识别(NER)
查看>>
NLP学习笔记:使用 Python 进行NLTK
查看>>
NLP:使用 SciKit Learn 的文本矢量化方法
查看>>
Nmap扫描教程之Nmap基础知识
查看>>
Nmap端口扫描工具Windows安装和命令大全(非常详细)零基础入门到精通,收藏这篇就够了
查看>>
NMAP网络扫描工具的安装与使用
查看>>
NMF(非负矩阵分解)
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>