4. search相关语法
searchApi概览¶
- URIsearch
GET /movies/_search?q=2012&df=title&sort=year:desc&from=0&size=10&timeout=1s
1 q 指定查询语句,使用Query String Syntax
2 df 默认字段,不指定时,会对所有字段进行查询
3 sort 排序 from 和size用于分页
4 Profile可以查看查询时如何被执行的
Query String Syntax¶
- 指定字段 OR 泛查询
q=title:2012 q=2012
# 泛查询对所有字段进行查询 GET /movies/_search?q=2012 { "profile":"true" } //// # 指定字段查询 GET /movies/_search?q=2012&df=title { "profile":"true" } 或者 GET /movies/_search?q=title:2012 { "profile":"true" }
-
Beautiful Mind 等效于 Beautiful OR Mind
-
"Beautiful Mind" 等效与Beautiful AND Mind Phrase要求顺序保持一致
#使用引号,Phrase查询 GET /movies/_search?q=title:"Beautiful Mind" { "profile":"true" } // # GET /movies/_search?q=title:Beautiful Mind { "profile":"true" }
title:(Beautiful Mind)
title="Beautiful Mind"
- 布尔操作 AND OR NOT 必须大写
title:(Beautiful OR Mind)
-
分组
-
表示must
-
表示 must_not
title:(+ase -def)
# 查找美丽心灵 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" }
year: >=1890
year:[1234 TO 3456]
GET /movies/_search?q=title:beautiful AND year:[2002 TO 2018] { "profile":"true" }
- 通配符查询
? *
GET /movies/_search?q=title:b* { "profile":"true" }
- 正则表达式
title:[ad]xy
- 模糊近似度匹配
GET /movies/_search?q=title:beautifl~1 { "profile":"true" } GET /movies/_search?q=title:"Lord Rings"~2 { "profile":"true" }