match_all
匹配所有文档,默认分页查询,只显示后十条数据,如下所示在索引中的数据有11条数据,在进行match_all查询时只返回了十条数据.
"total": {
"value": 11,
"relation": "eq"
}
GET /es_db/_search
{
"query": {
"match_all": {
}
}
}
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 11,
"relation": "eq"
},
"max_score": 1,
"hits": [
{
"_index": "es_db",
"_id": "10",
"_score": 1,
"_source": {
"name": "开人员",
"sex": 1,
"age": 32,
"address": "武汉东湖高新区未来智汇城",
"remark": "golang developer"
}
},
{
"_index": "es_db",
"_id": "8",
"_score": 1,
"_source": {
"name": "张星",
"sex": 1,
"age": 32,
"address": "武汉东湖高新区未来智汇城",
"remark": "golang developer"
}
},
{
"_index": "es_db",
"_id": "6",
"_score": 1,
"_source": {
"name": "赵虎",
"sex": 1,
"age": 32,
"address": "长沙麓谷兴工国际产业园",
"remark": "java architect"
}
},
{
"_index": "es_db",
"_id": "5",
"_score": 1,
"_source": {
"name": "张龙",
"sex": 0,
"age": 19,
"address": "长沙麓谷企业广场",
"remark": "java architect assistant"
}
},
{
"_index": "es_db",
"_id": "7",
"_score": 1,
"_source": {
"name": "李虎",
"sex": 1,
"age": 32,
"address": "广州番禺节能科技园",
"remark": "java architect"
}
},
{
"_index": "es_db",
"_id": "3",
"_score": 1,
"_source": {
"name": "王五",
"sex": 0,
"age": 26,
"address": "广州白云山公园",
"remark": "php developer"
}
},
{
"_index": "es_db",
"_id": "1",
"_score": 1,
"_source": {
"name": "张三",
"sex": 1,
"age": 25,
"address": "广州天河公园",
"remark": "java developer"
}
},
{
"_index": "es_db",
"_id": "2",
"_score": 1,
"_source": {
"name": "李四",
"sex": 1,
"age": 28,
"address": "广州荔湾大厦",
"remark": "java assistant"
}
},
{
"_index": "es_db",
"_id": "4",
"_score": 1,
"_source": {
"name": "赵六",
"sex": 0,
"age": 22,
"address": "长沙橘子洲",
"remark": "python assistant"
}
},
{
"_index": "es_db",
"_id": "11",
"_score": 1,
"_source": {
"name": "企业人员",
"sex": 1,
"age": 32,
"address": "武汉东湖高新区未来智汇城",
"remark": "golang developer"
}
}
]
}
}
如果想要指定分页查询可以使用from和size参数,如下所示,from表示从第几条记录开始分页,size表示每页展示几条数据
GET /es_db/_search
{
"query": {
"match_all": {
}
},
"from": 0,
"size": 11
}
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 11,
"relation": "eq"
},
"max_score": 1,
"hits": [
{
"_index": "es_db",
"_id": "10",
"_score": 1,
"_source": {
"name": "开人员",
"sex": 1,
"age": 32,
"address": "武汉东湖高新区未来智汇城",
"remark": "golang developer"
}
},
{
"_index": "es_db",
"_id": "8",
"_score": 1,
"_source": {
"name": "张星",
"sex": 1,
"age": 32,
"address": "武汉东湖高新区未来智汇城",
"remark": "golang developer"
}
},
{
"_index": "es_db",
"_id": "6",
"_score": 1,
"_source": {
"name": "赵虎",
"sex": 1,
"age": 32,
"address": "长沙麓谷兴工国际产业园",
"remark": "java architect"
}
},
{
"_index": "es_db",
"_id": "5",
"_score": 1,
"_source": {
"name": "张龙",
"sex": 0,
"age": 19,
"address": "长沙麓谷企业广场",
"remark": "java architect assistant"
}
},
{
"_index": "es_db",
"_id": "7",
"_score": 1,
"_source": {
"name": "李虎",
"sex": 1,
"age": 32,
"address": "广州番禺节能科技园",
"remark": "java architect"
}
},
{
"_index": "es_db",
"_id": "3",
"_score": 1,
"_source": {
"name": "王五",
"sex": 0,
"age": 26,
"address": "广州白云山公园",
"remark": "php developer"
}
},
{
"_index": "es_db",
"_id": "1",
"_score": 1,
"_source": {
"name": "张三",
"sex": 1,
"age": 25,
"address": "广州天河公园",
"remark": "java developer"
}
},
{
"_index": "es_db",
"_id": "2",
"_score": 1,
"_source": {
"name": "李四",
"sex": 1,
"age": 28,
"address": "广州荔湾大厦",
"remark": "java assistant"
}
},
{
"_index": "es_db",
"_id": "4",
"_score": 1,
"_source": {
"name": "赵六",
"sex": 0,
"age": 22,
"address": "长沙橘子洲",
"remark": "python assistant"
}
},
{
"_index": "es_db",
"_id": "11",
"_score": 1,
"_source": {
"name": "企业人员",
"sex": 1,
"age": 32,
"address": "武汉东湖高新区未来智汇城",
"remark": "golang developer"
}
},
{
"_index": "es_db",
"_id": "9",
"_score": 1,
"_source": {
"name": "泥马勒戈壁",
"sex": 1,
"age": 32,
"address": "武汉东湖高新区未来智汇城",
"remark": "golang developer"
}
}
]
}
}
_source
返回字段限制,如下所示,如果只想显示name和index字段可以以以下方式进行查询
GET /es_db/_search
{
"_source": ["name", "age"],
"query": {
"match_all": {
}
}
}
查询结果
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 11,
"relation": "eq"
},
"max_score": 1,
"hits": [
{
"_index": "es_db",
"_id": "10",
"_score": 1,
"_source": {
"name": "开人员",
"age": 32
}
},
{
"_index": "es_db",
"_id": "8",
"_score": 1,
"_source": {
"name": "张星",
"age": 32
}
},
{
"_index": "es_db",
"_id": "6",
"_score": 1,
"_source": {
"name": "赵虎",
"age": 32
}
},
{
"_index": "es_db",
"_id": "5",
"_score": 1,
"_source": {
"name": "张龙",
"age": 19
}
},
{
"_index": "es_db",
"_id": "7",
"_score": 1,
"_source": {
"name": "李虎",
"age": 32
}
},
{
"_index": "es_db",
"_id": "3",
"_score": 1,
"_source": {
"name": "王五",
"age": 26
}
},
{
"_index": "es_db",
"_id": "1",
"_score": 1,
"_source": {
"name": "张三",
"age": 25
}
},
{
"_index": "es_db",
"_id": "2",
"_score": 1,
"_source": {
"name": "李四",
"age": 28
}
},
{
"_index": "es_db",
"_id": "4",
"_score": 1,
"_source": {
"name": "赵六",
"age": 22
}
},
{
"_index": "es_db",
"_id": "11",
"_score": 1,
"_source": {
"name": "企业人员",
"age": 32
}
}
]
}
}
标签:index,name,db,source,DSL,score,Query,es
From: https://www.cnblogs.com/lyraHeartstrings/p/18055715