DSL-全量查询
# 请求
查询所有文档
在 Postman 中,向 ES 服务器发 GET 请求
GET http://localhost:9200/student/_search
1
body
- query 代表一个查询对象,里面可以有不同的查询属性
- match_all 查询类型,如:match_all(代表查询所有), match,term , range 等等
- {查询条件}:查询条件会根据类型的不同,写法也有差异
{
"query":{
"match_all":{}
}
}
1
2
3
4
5
2
3
4
5
response
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 5,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "student",
"_type": "_doc",
"_id": "1001",
"_score": 1.0,
"_source": {
"name": "zhangsan",
"nickname": "zhangsan",
"sex": "男",
"age": 30
}
},
{
"_index": "student",
"_type": "_doc",
"_id": "1002",
"_score": 1.0,
"_source": {
"name": "lisi",
"nickname": "lisi",
"sex": "男",
"age": 20
}
},
{
"_index": "student",
"_type": "_doc",
"_id": "1003",
"_score": 1.0,
"_source": {
"name": "wangwu",
"nickname": "wangwu",
"sex": "女",
"age": 40
}
},
{
"_index": "student",
"_type": "_doc",
"_id": "1004",
"_score": 1.0,
"_source": {
"name": "zhangsan1",
"nickname": "zhangsan1",
"sex": "女",
"age": 50
}
},
{
"_index": "student",
"_type": "_doc",
"_id": "1005",
"_score": 1.0,
"_source": {
"name": "zhangsan2",
"nickname": "zhangsan2",
"sex": "女",
"age": 30
}
}
]
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# 结果分析
{
"took" : 1116, // 查询花费时间,单位毫秒
"timed_out" : false, // 是否超时
"_shards" : { // 分片信息
"total" : 1, // 总数
"successful" : 1, // 成功
"skipped" : 0, // 忽略
"failed" : 0 // 失败
},
"hits" : { // 搜索命中结果
"total": { // 搜索条件匹配的文档总数
"value": 3, // 总命中计数的值
"relation": "eq" // 计数规则 eq 表示计数准确, gte 表示计数不准确
},
"max_score" : 1.0, // 匹配度分值
"hits" : [ // 命中结果集合
...
}
]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Last Updated: 2022/02/05, 15:58:51