1. Query
1. Query all indexes
get /_cat/indices?v
2. Query (match_all) all documents
get /movie/_search
1.匹配所有的文档
{
"query": {
"match_all": {}
}
}
2.匹配所有的文档且限制条数(其中如果未指定size,默认为10)
{
"query": {
"match_all": {}
},
"size": 1
}
3.匹配所有的文档且限制条数与游标,取出固定位置的几个数据
{
"query": {
"match_all": {}
},
"from": 10,
"size": 5
}
4.匹配所有的文档,按照某个值排序,限制条数与游标
{
"query": {
"match_all": {}
},
"from": 10,
"size": 5,
"sort": {
"balance": {
"age": "desc"
}
}
}
5.匹配文档返回固定字段,在source中添加
{
"query": {
"match_all": {}
},
"_source": [
"title",
"description"
],
"from": 10,
"size": 5
}
3. Match query (match) searches for a specific field or a set of fields
(Solve the problem that the match query is cut into words, it is very clear about the difference between term and match in es - short book )
1.搜索字段中包含关键字或值等于的情况
{
"query": {
"match": {
"age": 24
}
}
}
2.搜索字段中包含【动态sql】或者【电商】的文档
{
"query": {
"match": {
"title": "动态sql 电商"
}
}
}
4. Boolean query:
1.基础布尔查询
{
"query": {
"bool": {
"must": [
{"match": {"title": "画棵樱花树"}},
{"match": {"title": "送给自己吧"}}
]
}
}
}
2.布尔查询必须包含和不能包含
{
"query": {
"bool": {
"must": [
{"match": {"title": "画棵樱花树"}},
{"match": {"title": "送给自己吧"}}
],
"must_not": [
{"match": {"title": "单恋"}},
{"match": {"title": "双重树结构"}}
]
}
}
}
3.