Request Body查询
query
- match 单条件查询
- query_string 多字段 AND、OR条件查询
- multi_match 多字段查询
- match_phrase 短语匹配查询
_source
查询部分列
sort
排序
分页
from:从第n个开始
size:数量
查询包含beautiful,mind的电影
GET movies/_search
{
"query": {
"match": {
"title": "beautiful mind"
}
}
}
查询名字中包含beautiful mind短语的电影
GET movies/_search
{
"query": {
"match_phrase": {
"title": "beautiful mind"
}
}
}
查询2016-2018年的电影,并按照年份排序
GET movies/_search
{
"query": {
"range": {
"year": {
"gte": 2016,
"lte": 2018
}
}
},
"sort": [
{
"year": {
"order": "desc"
}
}
]
}
- lt:less than
- lte:less than or equals
- gt:greater than
- gte:greater than or equals
- eq:equals
- desc 降序
- asc 升序
只查询部分列
GET movies/_search
{
"_source": ["title","year"]
}
多字段同时匹配某些字符串
GET movies/_search
{
"query": {
"multi_match": {
"query": "beautiful mind Romance",
"fields": ["title", "genre"],
"type": "best_fields"
}
}
}
其中type的值有三个:
- most_fields:在多字段中匹配的越多排名越靠前
- best_fields: 能完全匹配的文档,排名越靠前。
- cross_fields: 查询越分散,排名越靠前。
查询既包含beautiful又包含mind的电影,使用query_string
。
GET movies/_search
{
"query": {
"query_string": {
"default_field": "title",
"query": "Beautiful Mind",
"default_operator": "AND" #不加默认是OR
}
}
}
GET movies/_search
{
"query": {
"query_string": {
"fields": ["title", "genre"],
"query": "Beautiful Mind",
"default_operator": "AND"
}
}
}
本文由 guoxiaorui 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: Aug 28, 2020 at 11:49 pm