04 | Search API概览

逸兴
逸兴
逸兴
57
文章
25
评论
2020-04-0212:14:4232 1475字阅读4分55秒

Search API 的分类

ElasticSearch 的查询api分为两大类 URL Search 和 Request Body Search

  • URL Search
    • http get 的方式
    • url中使用查询参数
  • Request Body Search
    • ElasticSearch 提供的,基于 json格式的更完备的查询语言,get post

指定查询索引

/_search集群上的所有索引
/index1/_searchindex1索引中查询
/index1,index2/_search在index1和index2 索引中查询
/index*/_search可使用通配符 index* 中查询

URl 查询的样例

04 | Search API概览

所有索引
中的
customer_first_name
这个字段中搜索值为
Eddit
的文档

04 | Search API概览

指定字段查询可使用上面的 q=查询字段:查询值

或则使用df字段

指定字段查询

04 | Search API概览
# 查询示例
#基本查询
GET /movies/_search?q=2012&df=title&sort=year:desc&from=0&size=10&timeout=1s

#带profile , 如果不指定字段,es会对文档中的所有字段进行查询,性能降低
GET /movies/_search?q=2012&df=title
{
	"profile":"true"
}


#泛查询,正对_all,所有字段
GET /movies/_search?q=2012
{
	"profile":"true"
}

#指定字段
GET /movies/_search?q=title:2012&sort=year:desc&from=0&size=10&timeout=1s
{
	"profile":"true"
}

Term Query & Phrase Query

04 | Search API概览
#使用引号,Phrase查询
GET /movies/_search?q=title:"Beautiful Mind"
{
	"profile":"true"
}

# 查找美丽心灵, Mind为泛查询
GET /movies/_search?q=title:Beautiful Mind
{
	"profile":"true"
}

#分组,Bool查询
GET /movies/_search?q=title:(Beautiful Mind)
{
	"profile":"true"
}
04 | Search API概览
04 | Search API概览
#布尔操作符
# 查找美丽心灵
GET /movies/_search?q=title:(Beautiful AND Mind)
{
	"profile":"true"
}

# 查找美丽心灵
GET /movies/_search?q=title:(Beautiful NOT Mind)
{
	"profile":"true"
}

# 查找美丽心灵
GET /movies/_search?q=title:(Beautiful %2BMind)
{
	"profile":"true"
}
04 | Search API概览
#范围查询 ,区间写法
GET /movies/_search?q=title:beautiful AND year:[2002 TO 2018%7D
{
	"profile":"true"
}
04 | Search API概览
#通配符查询
GET /movies/_search?q=title:b*
{
	"profile":"true"
}

//模糊匹配&近似度匹配
GET /movies/_search?q=title:beautifl~1
{
	"profile":"true"
}

GET /movies/_search?q=title:"Lord Rings"~2
{
	"profile":"true"
}

Request Body 样例

04 | Search API概览

返回信息:

04 | Search API概览



https://www.hugbg.com/archives/1978.html
逸兴
  • 本文由 发表于 2020-04-0212:14:42
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
自动更新SSL证书 默认分类

自动更新SSL证书

现在免费的SSL证书只有三个月有效期,有一个博客和图床都用的ssl证书到期需要重新签发,挺麻烦的。原本想着写个脚本通过阿里云的 OpenAPI 进行证书的签发和部署,但是偶然发现了 ACME 这个项目...
推导式、生成式与生成器 基础语法

推导式、生成式与生成器

推导式 概述 Python中的推导式是一种快速、简洁的数据结构创建方式,不需要手动创建数据结构中的每一个元素,类似于给出一个规律,python会根据这个规律自动填充数据结构。支持有列表推导式、字典推导...
CVE-2024-38077 Windows RDL漏洞检测修复方法(末尾) 默认分类

CVE-2024-38077 Windows RDL漏洞检测修复方法(末尾)

一、漏洞详情 Windows Server是由微软开发的操作系统系列,专为服务器环境设计,用于管理网络、数据存储和应用程序的运行。它为企业和组织提供了稳定、可靠的服务器平台,支持各种规模的网络基础设施...
Django DRF禁用URL末尾斜杆(:) 点点滴滴

Django DRF禁用URL末尾斜杆(:)

一、关于URL末尾斜杆 比如http://127.0.0.1:8000/api/v1/register 和 http://127.0.0.1:8000/api/v1/register/, 这两个是同一...
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

评论:3   其中:访客  3   博主  0
    • 你大爷 你大爷 3

      我们总是喜欢拿“顺其自然”来敷衍人生道路上的荆棘坎坷,却很少承认,真正的顺其自然,其实是竭尽所能之后的不强求,而非两手一摊的不作为。 —网易云 花びらの刻

      • 你大爷 你大爷 3

        人生的真理,只是藏在平淡无味之中。 —佛教禅语

        • 你大爷 你大爷 3

          弱小和无知,都不是生存的障碍,傲慢才是。 —三体