看视频的时候顺便记下,怕以后忘记。
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"
}