查询所有以cust开头的索引
GET /cust*/_search?pretty
返回bank索引中的所有的文档:
GET /bank/_search?q=*&pretty
等同于:
POST /bank/_search?pretty
{
"query": {"match_all": {}}
}
指定返回第11到第20个文档,并指定返回字段:
POST /bank/_search?pretty
{
"query": {"match_all": {}},
"from": 10,
"size":1,
"_source": ["account_number", "balance"]
}
- query:查询条件
- size:可制定返回的条数,不指定默认10
- from 指定从第几个开始返回
- _source指定返回的字段
Bool查询
Bool查询现在包括四种子句,must,filter,should,must_not.
- must:文档 必须 匹配这些条件才能被包含进来。
- must_not:文档 必须不 匹配这些条件才能被包含进来。
- should:如果满足这些语句中的任意语句,将增加 _score ,否则,无任何影响。它们主要用于修正每个文档的相关性得分。
- filter:必须 匹配,但它以不评分、过滤模式来进行。这些语句对评分没有贡献,只是根据过滤标准来排除或包含文档。
多条件查询:
查询customer索引下的externaltype中,name为Johne或tina,age从0到50
GET /customer/external/_search?pretty
{
"query": {
"bool": {
"must": [
{"match": {
"name": "Johne tina"
}},
{
"range": {
"age": {
"from": 0,
"to": 50
}
}
}
]
}
}
}
out:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1.287682,
"hits": [
{
"_index": "customer",
"_type": "extrnal",
"_id": "1",
"_score": 1.287682,
"_source": {
"name": "tina",
"age": 20
}
}
]
}
}
聚合查询:
将must改为should
range:范围查询
- gt 大于
- gte 大于等于
- lt 小于
- lte 小于等于