DSL-匹配查询
# 匹配查询 match
匹配类型查询,会把查询条件进行分词,然后进行查询,多个词条之间是 or 的关系
在 Postman 中,向 ES 服务器发 GET 请求
GET http://localhost:9200/student/_search
1
body json
{
"query":{
"match":{
"name":"zhangsan"
}
}
}
1
2
3
4
5
6
7
2
3
4
5
6
7
response
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 1.540445,
"hits": [
{
"_index": "student",
"_type": "_doc",
"_id": "1001",
"_score": 1.540445,
"_source": {
"name": "zhangsan",
"nickname": "zhangsan",
"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
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
# 多字段匹配查询 multi_match
multi_match 与 match 类似,不同的是它可以在多个字段中查询,也会有分词操作,多个词条之间是 or 的关系 在 Postman 中,向 ES 服务器发 GET 请求
GET http://localhost:9200/student/_search
1
body
{
"query": {
"multi_match": {
"query": "zhangsan",
"fields": ["name","nickname"]
}
}
}
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
response
{
"took": 11,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 1.540445,
"hits": [
{
"_index": "student",
"_type": "_doc",
"_id": "1001",
"_score": 1.540445,
"_source": {
"name": "zhangsan",
"nickname": "zhangsan",
"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
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
Last Updated: 2022/02/05, 15:58:51