Elasticsearch入门之Http操作(高级查询)

这篇具有很好参考价值的文章主要介绍了Elasticsearch入门之Http操作(高级查询)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

Elasticsearch 基本操作

Http操作:

高级查询:

高级查询:Elasticsearch 提供了基于 JSON 提供完整的查询 DSL 来定义查询

初始化数据:

es http查询,ElasticSearch,elasticsearch,搜索引擎

查询所有文档:

在 Postman 中,向 ES 服务器发 GET 请求 :http://172.18.20.254:9200/shopping/_search
es http查询,ElasticSearch,elasticsearch,搜索引擎
es http查询,ElasticSearch,elasticsearch,搜索引擎
返回值:
es http查询,ElasticSearch,elasticsearch,搜索引擎
返回值解释:
es http查询,ElasticSearch,elasticsearch,搜索引擎

匹配查询:

match 匹配类型查询,会把查询条件进行分词,然后进行查询,多个词条之间是 or 的关系

在 Postman 中,向 ES 服务器发 GET 请求 :http://172.18.20.254:9200/shopping/_search

es http查询,ElasticSearch,elasticsearch,搜索引擎返回结果为:
es http查询,ElasticSearch,elasticsearch,搜索引擎

字段匹配查询:

multi_match 与 match 类似,不同的是它可以在多个字段中查询

在 Postman 中,向 ES 服务器发 GET 请求 :http://172.18.20.254:9200/shopping/_search

es http查询,ElasticSearch,elasticsearch,搜索引擎
返回结果为:
es http查询,ElasticSearch,elasticsearch,搜索引擎

关键字精确查询:

term 查询,精确的关键词匹配查询,不对查询条件进行分词

在 Postman 中,向 ES 服务器发 GET 请求 :http://172.18.20.254:9200/shopping/_search

es http查询,ElasticSearch,elasticsearch,搜索引擎
返回结果为:
es http查询,ElasticSearch,elasticsearch,搜索引擎

多关键字精确查询:

terms 查询和 term 查询一样,但它允许你指定多值进行匹配。

如果这个字段包含了指定值中的任何一个值,那么这个文档满足条件,类似于 mysql 的 in

在 Postman 中,向 ES 服务器发 GET 请求 :http://172.18.20.254:9200/shopping/_search

es http查询,ElasticSearch,elasticsearch,搜索引擎
返回结果为:
es http查询,ElasticSearch,elasticsearch,搜索引擎

指定查询字段:

默认情况下,Elasticsearch 在搜索的结果中,会把文档中保存在_source 的所有字段都返回。

如果我们只想获取其中的部分字段,我们可以添加_source 的过滤

在 Postman 中,向 ES 服务器发 GET 请求 :http://172.18.20.254:9200/shopping/_search

es http查询,ElasticSearch,elasticsearch,搜索引擎
返回结果为:
es http查询,ElasticSearch,elasticsearch,搜索引擎

过滤字段:

我们也可以通过:includes:来指定想要显示的字段、excludes:来指定不想要显示的字段

在 Postman 中,向 ES 服务器发 GET 请求 :http://172.18.20.254:9200/shopping/_search

es http查询,ElasticSearch,elasticsearch,搜索引擎
返回结果为:
es http查询,ElasticSearch,elasticsearch,搜索引擎

组合查询:

bool把各种其它查询通过must(必须 )、must_not(必须不)、should(应该)的方式进行组合

在 Postman 中,向 ES 服务器发 GET 请求 :http://172.18.20.254:9200/shopping/_search

es http查询,ElasticSearch,elasticsearch,搜索引擎
返回结果:
es http查询,ElasticSearch,elasticsearch,搜索引擎

范围查询:

range 查询找出那些落在指定区间内的数字或者时间。range 查询允许以下字符

es http查询,ElasticSearch,elasticsearch,搜索引擎
在 Postman 中,向 ES 服务器发 GET 请求 :http://172.18.20.254:9200/shopping/_search

es http查询,ElasticSearch,elasticsearch,搜索引擎
返回结果:
es http查询,ElasticSearch,elasticsearch,搜索引擎

模糊查询:

返回包含与搜索字词相似的字词的文档。

在 Postman 中,向 ES 服务器发 GET 请求 :http://172.18.20.254:9200/shopping/_search

es http查询,ElasticSearch,elasticsearch,搜索引擎
返回结果:
es http查询,ElasticSearch,elasticsearch,搜索引擎

单字段排序:

sort 可以让我们按照不同的字段进行排序,并且通过 order 指定排序的方式。desc 降序,asc升序。

在 Postman 中,向 ES 服务器发 GET 请求 :http://172.18.20.254:9200/shopping/_search
es http查询,ElasticSearch,elasticsearch,搜索引擎
返回结果:
es http查询,ElasticSearch,elasticsearch,搜索引擎

高亮查询:

在进行关键字搜索时,搜索出的内容中的关键字会显示不同的颜色,称之为高亮

在Bing搜索“京东”

es http查询,ElasticSearch,elasticsearch,搜索引擎
Elasticsearch 可以对查询内容中的关键字部分,进行标签和样式(高亮)的设置。
在使用 match 查询的同时,加上一个 highlight 属性:

  • pre_tags:前置标签
  • post_tags:后置标签
  • fields:需要高亮的字段
  • title:这里声明 title 字段需要高亮,后面可以为这个字段设置特有配置,也可以空

在 Postman 中,向 ES 服务器发 GET 请求 :http://172.18.20.254:9200/shopping/_search

es http查询,ElasticSearch,elasticsearch,搜索引擎
返回结果:
es http查询,ElasticSearch,elasticsearch,搜索引擎

分页查询:
  • from:当前页的起始索引,默认从 0 开始。 from = (pageNum - 1) * size
  • size:每页显示多少条

在 Postman 中,向 ES 服务器发 GET 请求 :http://172.18.20.254:9200/shopping/_search
es http查询,ElasticSearch,elasticsearch,搜索引擎
返回结果:
es http查询,ElasticSearch,elasticsearch,搜索引擎

聚合查询:

聚合允许使用者对 es 文档进行统计分析,类似与关系型数据库中的 group by,当然还有很多其他的聚合,例如取最大值、平均值等等。

在 Postman 中,向 ES 服务器发 GET 请求 :http://172.18.20.254:9200/shopping/_search

对某个字段取最大值 max:

es http查询,ElasticSearch,elasticsearch,搜索引擎
在 Postman 中,向 ES 服务器发 GET 请求 :http://172.18.20.254:9200/shopping/_search

对某个字段取最小值 min:

es http查询,ElasticSearch,elasticsearch,搜索引擎

对某个字段求和 sum:

es http查询,ElasticSearch,elasticsearch,搜索引擎

对某个字段取平均值 avg:

es http查询,ElasticSearch,elasticsearch,搜索引擎

对某个字段的值进行去重之后再取总数:

es http查询,ElasticSearch,elasticsearch,搜索引擎

State 聚合:
  • stats 聚合,对某个字段一次性返回 count,max,min,avg 和 sum 五个指标

es http查询,ElasticSearch,elasticsearch,搜索引擎

桶聚合查询:

桶聚合相当于 sql 中的 group by 语句

在 Postman 中,向 ES 服务器发 GET 请求 :http://172.18.20.254:9200/shopping/_search

terms 聚合,分组统计

es http查询,ElasticSearch,elasticsearch,搜索引擎
返回结果:
es http查询,ElasticSearch,elasticsearch,搜索引擎

在 terms 分组下再进行聚合

es http查询,ElasticSearch,elasticsearch,搜索引擎
返回结果:
es http查询,ElasticSearch,elasticsearch,搜索引擎文章来源地址https://www.toymoban.com/news/detail-784762.html

到了这里,关于Elasticsearch入门之Http操作(高级查询)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

  • 七、ElasticSearch-高级查询操作三

    在进行搜索时,搜索出的内容中的会显示不同的颜色,称之为高亮。 Elasticsearch 可以对查询内容中的部分,进行标签和样式 ( 高亮 ) 的设置。 在使用 match 查询的同时,加上一个 highlight 属性: pre_tags :前置标签 post_tags :后置标签 fields :需要高亮的字段

    2023年04月08日
    浏览(9)
  • 【ElasticSearch-基础篇】ES高级查询Query DSL术语级别查询并结合springboot使用

    Elasticsearch 提供了基于 JSON 的完整 Query DSL(Domain Specific Language)来定义查询。 因Query DSL是利用Rest API传递JSON格式的请求体(RequestBody)数据与ES进行交互,所以我们在使用springboot的时候也可以很方便的进行集成,本文主要讲述的就是使用springboot实现各类DSL的语法查询。 Elastics

    2024年02月01日
    浏览(11)
  • 从入门到进阶:Elasticsearch高级查询技巧详解

    Elasticsearch是一款功能强大的全文搜索引擎,它使用Lucene搜索库进行底层索引和搜索。Elasticsearch提供了许多高级查询技巧,可以帮助用户更准确、更高效地查询数据。本教程将介绍Elasticsearch的高级查询技巧,并提供一些示例代码来说明它们的使用。 Elasticsearch支持布尔查询,

    2024年02月06日
    浏览(12)
  • Elasticsearch7.8.0版本入门—— 高亮查询文档(高级查询)

    Elasticsearch7.8.0版本入门—— 高亮查询文档(高级查询)

    在 Postman 中,向 ES 服务器发 POST 请求 :http://localhost:9200/user/_doc/ 1 ,请求体内容为: 在 Postman 中,向 ES 服务器发 POST 请求 :http://localhost:9200/user/_doc/ 2 ,请求体内容为: 在 Postman 中,向 ES 服务器发 POST 请求 :http://localhost:9200/user/_doc/ 3 ,请求体内容为: 在 Postman 中,向

    2024年02月01日
    浏览(14)
  • Elasticsearch7.8.0版本入门—— 完全匹配查询文档(高级查询)

    Elasticsearch7.8.0版本入门—— 完全匹配查询文档(高级查询)

    在 Postman 中,向 ES 服务器发 POST 请求 :http://localhost:9200/user/_doc/ 1 ,请求体内容为: 在 Postman 中,向 ES 服务器发 POST 请求 :http://localhost:9200/user/_doc/ 2 ,请求体内容为: 在 Postman 中,向 ES 服务器发 POST 请求 :http://localhost:9200/user/_doc/ 3 ,请求体内容为: 在 Postman 中,向

    2023年04月24日
    浏览(15)
  • Elasticsearch(1)——倒排索引与HTTP操作Elasticsearch

    Elasticsearch(1)——倒排索引与HTTP操作Elasticsearch

    1 前言 Elastic Stack 核心产品包括 Elasticsearch【存储数据】、Kibana【展示数据】、Beats 和 Logstash【收集与传输数据】(也称为 ELK Stack)等等。能够安全可靠地从任何来源获取任何格式的数据,然后对数据进行搜索、分析和可视化。sa Elasticsearch 是一个分布式、RESTful 风格的搜索和

    2024年02月12日
    浏览(11)
  • (十)ElasticSearch高级使用【别名,重建索引,refresh操作,高亮查询,查询建议】

    在开发中,随着业务需求的迭代,较⽼的业务逻辑就要⾯临更新甚⾄是重构,⽽对于es来说,为了 适应新的业务逻辑,可能就要对原有的索引做⼀些修改,⽐如对某些字段做调整,甚⾄是重建索 引。⽽做这些操作的时候,可能会对业务造成影响,甚⾄是停机调整等问题。由此

    2024年02月02日
    浏览(49)
  • Elasticsearch ES操作:查询数据(全部、分页、单条)

    查询 条件查询 指定条数 返回结果

    2024年02月16日
    浏览(12)
  • Elasticsearch从入门到精通-05ES匹配查询

    Elasticsearch从入门到精通-05ES匹配查询

    👏作者简介:大家好,我是程序员行走的鱼 📖 本篇主要介绍和大家一块学习一下ES各种场景下的匹配查询,有助于我们在项目中进行综合使用 创建索引并指定ik分词器: 添加数据: 需要搜索的document中的remark字段包含java和developer词组 上述语法中,如果将operator的值改为or。则与

    2024年03月27日
    浏览(12)
  • Elasticsearch7.8.0版本入门—— 多关键字精确查询文档(高级查询)

    Elasticsearch7.8.0版本入门—— 多关键字精确查询文档(高级查询)

    在 Postman 中,向 ES 服务器发 POST 请求 :http://localhost:9200/user/_doc/ 1 ,请求体内容为: 在 Postman 中,向 ES 服务器发 POST 请求 :http://localhost:9200/user/_doc/ 2 ,请求体内容为: 在 Postman 中,向 ES 服务器发 POST 请求 :http://localhost:9200/user/_doc/ 3 ,请求体内容为: 在 Postman 中,向

    2024年02月16日
    浏览(11)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包