es 基础概念总结 —— URI Search
搜索 API
GET /<index>/_search POST /<index>/_search GET /_search POST /_search
同时在多个索引上查询
# 单个索引: GET /twitter/_search?q=tag:wow # 多个索引: GET /kimchy,elasticsearch/_search?q=user:kimchy # 全部索引: GET /_search?q=user:kimchy GET /_all/_search?q=user:kimchy GET /*/_search?q=user:kimchy
URI Search
GET /<index>/_search?q=<parameter>
泛查询(会对所有字段进行查询)
GET /movies/_search?q=2012
{
"profile":"true"
}
指定字段查询
GET /movies/_search?q=title:2012
{
"profile":"true"
}
phrase 查询
GET /movies/_search?q=title:"Beautiful Mind"
{
"profile":"true"
}
term 查询
注意:term 为精确查询,通常用于根据商品id或username等不需要分析器的字段进行相关查询。如果被查询的字段为 text,并且使用了某些分析器对字段进行处理(比如将一段中文分成一个个的单字),将会导致 term 什么也查不到。参考文档
说明:%2B 表示 +。其中 + 表示 must 必须包含,- 表示 must not 必须不包含。什么都没有,根据情况,可以是必须包含(当只有这一个条件时),也可以是可能包含(有其它条件时)。
# 等同 title:beautiful title:mind
GET /movies/_search?q=title:(Beautiful Mind)
{
"profile":"true"
}
# 等同 +title:beautiful +title:mind
GET /movies/_search?q=title:(Beautiful AND Mind)
{
"profile":"true"
}
# 等同 title:beautiful -title:mind
GET /movies/_search?q=title:(Beautiful NOT Mind) { "profile":"true" }
# 等同 title:beautiful +title:mind
GET /movies/_search?q=title:(Beautiful %2BMind) { "profile":"true" }
通配符查询
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"
}
区间查询
说明:%7D 表示 } 。其中 {} 是开区间, [] 是闭区间
GET /movies/_search?q=title:beautiful AND year:[2002 TO 2018%7D
{
"profile":"true"
}
相关文档
https://www.elastic.co/guide/en/elasticsearch/reference/7.6/search-uri-request.html
https://www.w3school.com.cn/tags/html_ref_urlencode.html
浙公网安备 33010602011771号