Elasticsearch URI Search

看视频的时候顺便记下,怕以后忘记。

URI Search - 通过URI query实现搜索

# q指定查询语句,使用Query String Syntax
# df默认字段,不指定时会对所有字段进行查询
# sort排序 / from和size用于分页
# Profile可以查看查询是如何被执行的
GET /movies/_search?q=2012&df=title&sort=year:desc&from=0&size=10&timeout=1s

# 带profile
GET movies/_search?q=2012&df=title
{
  "profile": "true"
}


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

# Term and Phrase
# Beautiful Mind等效于Beautiful OR Mind
# "Beautiful Mind", 等效于Beautiful AND Mind。Phrase查询,还要求前后顺序保持一致

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

# 查找Beatiful Mind,Mind为泛查询 Disjunction Max Query 指的是: 将任何与任一查询匹配的文档作为结果返回,但只将最佳匹配的评分作为查询的评分结果返回
GET /movies/_search?q=title:Beautiful Mind
{
  "profile": "true"
}

# Term query
# 分组,Bool查询
GET /movies/_search?q=title:(Beautiful Mind)
{
  "profile": "true"
}

# 分组与引号
# title:(Beatiful Mind)
# title="Beatiful Mind"

# AND
GET /movies/_search?q=title:(Beautiful AND Mind)
{
  "profile": "true"
}

# NOT
GET /movies/_search?q=title:(Beautiful NOT Mind)
{
  "profile": "true"
}

# %2B == + beautiful mind 查询字段title的值必须包含Mind的 如同时包含Beautiful的 相关性最高 最先顺序出现 (去掉Beautiful可对比结果)
GET /movies/_search?q=title:(Beautiful %2BMind)
{
  "profile": "true"
}


# 范围查询

# 范围查询,区间写法
GET /movies/_search?q=year:>=1980
{
  "profile": "true"
}

# >2017 <=2018
GET /movies/_search?q=year:{2016 TO 2018]
{
  "profile": "true"
}

# >=2016 <=2018
GET /movies/_search?q=year:[2016 TO 2018]
{
  "profile": "true"
}

# >2016 <2018
GET /movies/_search?q=year:{2016 TO 2018%7D
{
  "profile": "true"
}

GET /movies/_search?q=year:[* TO 2018]
{
  "profile": "true"
}

GET /movies/_search?q=year:>2017 TO <=2018
{
  "profile": "true"
}

# 通配符查询
GET /movies/_search?q=title:b*
{
  "profile": "true"
}

# 正则表达式查询
GET /movies/_search?q=title:/[bt]oy/
{
  "profile": "true"
}

# 模糊匹配&近似的匹配
GET /movies/_search?q=title:beatuifl~2
{
  "profile": "true"
}

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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值