# ES查询
# 新增数据
- URL:http://0.0.0.0:9200/
index_example
/type_example
/_id
- Method:
PUT
- 请求参数:
{
"sourceid": 2001,
"summary": "MEM利用率超过90%",
"severity": 1,
"citype": "2001",
"sourceeventid": "366d8cc1d9742f57",
"sourceseverity": 3,
"lastoccurrence": "2020-2-20 10:03:13",
"sourceciname": "esp_app02",
"kpiname": "MEM",
"status": 1
}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
- 响应内容:
{
"result": "created",
"_shards": {
"total": 2,
"failed": 0,
"successful": 1
},
"_seq_no": 2,
"_index": "index_example",
"_type": "type_example",
"_id": "1",
"_version": 1,
"_primary_term": 1
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
# 查询数据
# 关系型数据库与ES常用查询关键字对比
SQL关键字 | Elasticsearch关键字 | 说明 |
---|---|---|
where | query | 查询范围 |
order by | sort | 排序:升序asc、降序desc |
= | term | 判断等值、精确值查询,用它处理数字(numbers)、布尔值(Booleans)、日期(dates)以及文本(text) |
in | terms | 限定指定范围的查询 |
not null | exists | 判断某字段是否存在 |
> | gt | 大于 |
< | lt | 小于 |
>= | gte | 大于等于 |
<= | lte | 小于等于 |
top | size | 指定返回数据的条数,ES默认是10条,配合From可实现翻页效果 |
limit | from size | 分页 |
and | must | 必须包含 |
not | must not | 必须不包含 |
or | should | 至少有一个匹配 |
# sort查询
- URL:http://0.0.0.0:9200/
index_example
/_search
- Method:
POST
- DSL:
select * from index_example order by lastoccurrence desc
- 请求参数:
{
"query": {
"match_all": {}
},
"sort": [
{
"lastoccurrence": {
"order": "desc"
}
}
]
}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
- 响应内容:
{
"_shards": {
"total": 5,
"failed": 0,
"successful": 5,
"skipped": 0
},
"hits": {
"hits": [
{
"_index": "index_example",
"_type": "type_example",
"_source": {
"sourceid": 1006,
"summary": "MEM利用率超过90%",
"severity": 1,
"sourceeventid": "366d8cc1d9742f57",
"sourceseverity": 3,
"lastoccurrence": "2020-11-06 10:03:13",
"sourceciname": "esp_app02",
"kpiname": "MEM",
"citype": "1006",
"status": 1
},
"_id": "TL8B-nUBAdDIB8EgeoNG",
"sort": [
1604656993000
]
},
{
"_index": "index_example",
"_type": "type_example",
"_source": {
"sourceid": 2001,
"summary": "MEM利用率超过90%",
"severity": 1,
"sourceeventid": "366d8cc1d9742f57",
"sourceseverity": 3,
"lastoccurrence": "2020-2-20 10:03:13",
"sourceciname": "esp_app02",
"kpiname": "MEM",
"citype": "2001",
"status": 1
},
"_id": "1",
"sort": [
1582192993000
]
}
],
"total": 7
},
"took": 109,
"timed_out": false
}
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
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
# term查询
说明
term一般用于对ES field的精确匹配查找,类似于关系型数据库中的columA="value1"。在ES中对字符串精确查找,只能对keyword
类型的字段进行精确查找,如果对text
类型的field进行查询由于分词可能会导致查询结果不准。
- URL:http://0.0.0.0:9200/
index_example
/_search
- Method:
POST
- DSL:
select * from index_example where sourceciname="esp_app01"
- 请求参数_01:
{
"query": {
"term": {
"sourceciname.keyword": "esp_app01"
}
}
}
1
2
3
4
5
6
7
2
3
4
5
6
7
- 响应内容_01:
{
"_shards": {
"total": 5,
"failed": 0,
"successful": 5,
"skipped": 0
},
"hits": {
"hits": [
{
"_index": "index_example",
"_type": "type_example",
"_source": {
"sourceid": 1005,
"summary": "MEM利用率超过90%",
"severity": 1,
"sourceeventid": "366d8cc1d9742f57",
"sourceseverity": 3,
"lastoccurrence": "2020-11-05 10:03:13",
"sourceciname": "esp_app01",
"kpiname": "MEM",
"citype": "1005",
"status": 1
},
"_id": "S78B-nUBAdDIB8EgHYMd",
"_score": 0.9808292
},
{
"_index": "index_example",
"_type": "type_example",
"_source": {
"sourceid": 1003,
"summary": "CPU利用率超过90%",
"severity": 1,
"sourceeventid": "366d8cc1d9742f57",
"sourceseverity": 3,
"lastoccurrence": "2020-11-03 10:03:13",
"sourceciname": "esp_app01",
"kpiname": "CPU",
"citype": "1003",
"status": 1
},
"_id": "Sb8A-nUBAdDIB8EgWoNG",
"_score": 0.2876821
}
],
"total": 4,
"max_score": 0.9808292
},
"took": 0,
"timed_out": false
}
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
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
- DSL:
select * from index_example where kpiname="CPU"
- 请求参数_02:
{
"query": {
"term": {
"kpiname": "CPU"
}
}
}
1
2
3
4
5
6
7
2
3
4
5
6
7
- 响应内容_02:
{
"_shards": {
"total": 5,
"failed": 0,
"successful": 5,
"skipped": 0
},
"hits": {
"hits": [
{
"_index": "index_example",
"_type": "type_example",
"_source": {
"sourceid": 1001,
"summary": "CPU利用率超过90%",
"severity": 1,
"sourceeventid": "366d8cc1d9742f57",
"sourceseverity": 3,
"lastoccurrence": "2020-11-01 10:03:13",
"sourceciname": "esp_app01",
"kpiname": "CPU",
"citype": "1001",
"status": 1
},
"_id": "R7_0-XUBAdDIB8Egi4Or",
"_score": 0.47000363
},
{
"_index": "index_example",
"_type": "type_example",
"_source": {
"sourceid": 1003,
"summary": "CPU利用率超过90%",
"severity": 1,
"sourceeventid": "366d8cc1d9742f57",
"sourceseverity": 3,
"lastoccurrence": "2020-11-03 10:03:13",
"sourceciname": "esp_app01",
"kpiname": "CPU",
"citype": "1003",
"status": 1
},
"_id": "Sb8A-nUBAdDIB8EgWoNG",
"_score": 0.2876821
}
],
"total": 3,
"max_score": 0.47000363
},
"took": 0,
"timed_out": false
}
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
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
- DSL:
select * from index_example where sourceseverity=3
- 请求参数_03:
{
"query": {
"term": {
"sourceseverity": 3
}
}
}
1
2
3
4
5
6
7
2
3
4
5
6
7
- 响应内容_03:
{
"_shards": {
"total": 5,
"failed": 0,
"successful": 5,
"skipped": 0
},
"hits": {
"hits": [
{
"_index": "index_example",
"_type": "type_example",
"_source": {
"sourceid": 1003,
"summary": "CPU利用率超过90%",
"severity": 1,
"sourceeventid": "366d8cc1d9742f57",
"sourceseverity": 3,
"lastoccurrence": "2020-11-03 10:03:13",
"sourceciname": "esp_app01",
"kpiname": "CPU",
"citype": "1003",
"status": 1
},
"_id": "Sb8A-nUBAdDIB8EgWoNG",
"_score": 1
},
{
"_index": "index_example",
"_type": "type_example",
"_source": {
"sourceid": 1004,
"summary": "MEM利用率超过90%",
"severity": 1,
"sourceeventid": "366d8cc1d9742f57",
"sourceseverity": 3,
"lastoccurrence": "2020-11-04 10:03:13",
"sourceciname": "esp_app02",
"kpiname": "MEM",
"citype": "1004",
"status": 1
},
"_id": "Sr8A-nUBAdDIB8Eg1YOp",
"_score": 1
}
],
"total": 7,
"max_score": 1
},
"took": 1,
"timed_out": false
}
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
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
# terms查询
说明
terms一般用于对ES field的精确匹配查找,可以根据多个值的列表进行查找,类似于关系型数据库中的columnA in ("value1","value2")。在ES中对字符串精确查找,只能对keyword
类型的字段进行精确查找,如果对text
类型的field进行查询由于分词可能会导致查询结果不准。
- URL:http://0.0.0.0:9200/
index_example
/_search
- Method:
POST
- DSL:
select * from index_example where kpiname in ("CPU","MEM")
- 请求参数:
{
"query": {
"terms": {
"kpiname": [
"CPU",
"MEM"
]
}
}
}
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
- 响应内容:
{
"_shards": {
"total": 5,
"failed": 0,
"successful": 5,
"skipped": 0
},
"hits": {
"hits": [
{
"_index": "index_example",
"_type": "type_example",
"_source": {
"sourceid": 1003,
"summary": "CPU利用率超过90%",
"severity": 1,
"sourceeventid": "366d8cc1d9742f57",
"sourceseverity": 3,
"lastoccurrence": "2020-11-03 10:03:13",
"sourceciname": "esp_app01",
"kpiname": "CPU",
"citype": "1003",
"status": 1
},
"_id": "Sb8A-nUBAdDIB8EgWoNG",
"_score": 1
},
{
"_index": "index_example",
"_type": "type_example",
"_source": {
"sourceid": 1004,
"summary": "MEM利用率超过90%",
"severity": 1,
"sourceeventid": "366d8cc1d9742f57",
"sourceseverity": 3,
"lastoccurrence": "2020-11-04 10:03:13",
"sourceciname": "esp_app02",
"kpiname": "MEM",
"citype": "1004",
"status": 1
},
"_id": "Sr8A-nUBAdDIB8Eg1YOp",
"_score": 1
}
],
"total": 7,
"max_score": 1
},
"took": 0,
"timed_out": false
}
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
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
# exists查询
说明
判断field是否有值,类似于关系型数据库的is not null
。
- URL:http://0.0.0.0:9200/
index_example
/_search
- Method:
POST
- DSL:
select * from index_example where sourceseverity is not null
- 请求参数:
{
"query": {
"exists": {
"field": "sourceseverity"
}
}
}
1
2
3
4
5
6
7
2
3
4
5
6
7
- 响应内容:
{
"_shards": {
"total": 5,
"failed": 0,
"successful": 5,
"skipped": 0
},
"hits": {
"hits": [
{
"_index": "index_example",
"_type": "type_example",
"_source": {
"sourceid": 1003,
"summary": "CPU利用率超过90%",
"severity": 1,
"sourceeventid": "366d8cc1d9742f57",
"sourceseverity": 3,
"lastoccurrence": "2020-11-03 10:03:13",
"sourceciname": "esp_app01",
"kpiname": "CPU",
"citype": "1003",
"status": 1
},
"_id": "Sb8A-nUBAdDIB8EgWoNG",
"_score": 1
},
{
"_index": "index_example",
"_type": "type_example",
"_source": {
"sourceid": 1004,
"summary": "MEM利用率超过90%",
"severity": 1,
"sourceeventid": "366d8cc1d9742f57",
"sourceseverity": 3,
"lastoccurrence": "2020-11-04 10:03:13",
"sourceciname": "esp_app02",
"kpiname": "MEM",
"citype": "1004",
"status": 1
},
"_id": "Sr8A-nUBAdDIB8Eg1YOp",
"_score": 1
}
],
"total": 7,
"max_score": 1
},
"took": 0,
"timed_out": false
}
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
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
# gt lt查询
- URL:http://0.0.0.0:9200/
index_example
/_search
- Method:
POST
- DSL:
select * from index_example where sourceseverity > 1 and sourceseverity < 4
- 请求参数:
{
"query": {
"range": {
"sourceseverity": {
"gt": 1,
"lt": 4
}
}
}
}
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
- 响应内容:
{
"_shards": {
"total": 5,
"failed": 0,
"successful": 5,
"skipped": 0
},
"hits": {
"hits": [
{
"_index": "index_example",
"_type": "type_example",
"_source": {
"sourceid": 1003,
"summary": "CPU利用率超过90%",
"severity": 1,
"sourceeventid": "366d8cc1d9742f57",
"sourceseverity": 3,
"lastoccurrence": "2020-11-03 10:03:13",
"sourceciname": "esp_app01",
"kpiname": "CPU",
"citype": "1003",
"status": 1
},
"_id": "Sb8A-nUBAdDIB8EgWoNG",
"_score": 1
},
{
"_index": "index_example",
"_type": "type_example",
"_source": {
"sourceid": 1004,
"summary": "MEM利用率超过90%",
"severity": 1,
"sourceeventid": "366d8cc1d9742f57",
"sourceseverity": 3,
"lastoccurrence": "2020-11-04 10:03:13",
"sourceciname": "esp_app02",
"kpiname": "MEM",
"citype": "1004",
"status": 1
},
"_id": "Sr8A-nUBAdDIB8Eg1YOp",
"_score": 1
}
],
"total": 7,
"max_score": 1
},
"took": 0,
"timed_out": false
}
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
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
# size查询
说明
一般和sort
配合使用,类似于关系型数据库中的Top-N
查询。
- URL:http://0.0.0.0:9200/
index_example
/_search
- Method:
POST
- DSL:
select * from index_example order by lastoccurrence desc limit 0,3
- 请求参数:
{
"size": 3,
"query": {
"match_all": {}
},
"sort": [
{
"lastoccurrence": {
"order": "desc"
}
}
]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
- 响应内容:
{
"_shards": {
"total": 5,
"failed": 0,
"successful": 5,
"skipped": 0
},
"hits": {
"hits": [
{
"_index": "index_example",
"_type": "type_example",
"_source": {
"sourceid": 1006,
"summary": "MEM利用率超过90%",
"severity": 1,
"sourceeventid": "366d8cc1d9742f57",
"sourceseverity": 3,
"lastoccurrence": "2020-11-06 10:03:13",
"sourceciname": "esp_app02",
"kpiname": "MEM",
"citype": "1006",
"status": 1
},
"_id": "TL8B-nUBAdDIB8EgeoNG",
"sort": [
1604656993000
]
},
{
"_index": "index_example",
"_type": "type_example",
"_source": {
"sourceid": 1005,
"summary": "MEM利用率超过90%",
"severity": 1,
"sourceeventid": "366d8cc1d9742f57",
"sourceseverity": 3,
"lastoccurrence": "2020-11-05 10:03:13",
"sourceciname": "esp_app01",
"kpiname": "MEM",
"citype": "1005",
"status": 1
},
"_id": "S78B-nUBAdDIB8EgHYMd",
"sort": [
1604570593000
]
},
{
"_index": "index_example",
"_type": "type_example",
"_source": {
"sourceid": 1004,
"summary": "MEM利用率超过90%",
"severity": 1,
"sourceeventid": "366d8cc1d9742f57",
"sourceseverity": 3,
"lastoccurrence": "2020-11-04 10:03:13",
"sourceciname": "esp_app02",
"kpiname": "MEM",
"citype": "1004",
"status": 1
},
"_id": "Sr8A-nUBAdDIB8Eg1YOp",
"sort": [
1604484193000
]
}
],
"total": 7
},
"took": 0,
"timed_out": false
}
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
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
# from size查询
- URL:http://0.0.0.0:9200/
index_example
/_search
- Method:
POST
- DSL:
select * from index_example limit 1,2
- 请求参数:
{
"from": 1,
"size": 2,
"query": {
"match_all": {}
}
}
1
2
3
4
5
6
7
2
3
4
5
6
7
- 响应内容:
{
"_shards": {
"total": 5,
"failed": 0,
"successful": 5,
"skipped": 0
},
"hits": {
"hits": [
{
"_index": "index_example",
"_type": "type_example",
"_source": {
"sourceid": 1005,
"summary": "MEM利用率超过90%",
"severity": 1,
"sourceeventid": "366d8cc1d9742f57",
"sourceseverity": 3,
"lastoccurrence": "2020-11-05 10:03:13",
"sourceciname": "esp_app01",
"kpiname": "MEM",
"citype": "1005",
"status": 1
},
"_id": "S78B-nUBAdDIB8EgHYMd",
"_score": 1
},
{
"_index": "index_example",
"_type": "type_example",
"_source": {
"sourceid": 1006,
"summary": "MEM利用率超过90%",
"severity": 1,
"sourceeventid": "366d8cc1d9742f57",
"sourceseverity": 3,
"lastoccurrence": "2020-11-06 10:03:13",
"sourceciname": "esp_app02",
"kpiname": "MEM",
"citype": "1006",
"status": 1
},
"_id": "TL8B-nUBAdDIB8EgeoNG",
"_score": 1
}
],
"total": 7,
"max_score": 1
},
"took": 0,
"timed_out": false
}
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
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
# must查询
说明
条件组合查询,类似于关系型数据库中的and
关键字。
- URL:http://0.0.0.0:9200/
index_example
/_search
- Method:
POST
- DSL:
select * from index_example where sourceseverity=3 and kpiname="MEM"
- 请求参数:
{
"query": {
"bool": {
"must": [
{
"term": {
"sourceseverity": 3
}
},
{
"term": {
"kpiname": "MEM"
}
}
]
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- 响应参数:
{
"_shards": {
"total": 5,
"failed": 0,
"successful": 5,
"skipped": 0
},
"hits": {
"hits": [
{
"_index": "index_example",
"_type": "type_example",
"_source": {
"sourceid": 1004,
"summary": "MEM利用率超过90%",
"severity": 1,
"sourceeventid": "366d8cc1d9742f57",
"sourceseverity": 3,
"lastoccurrence": "2020-11-04 10:03:13",
"sourceciname": "esp_app02",
"kpiname": "MEM",
"citype": "1004",
"status": 1
},
"_id": "Sr8A-nUBAdDIB8Eg1YOp",
"_score": 1.9808292
}
],
"total": 4,
"max_score": 1.9808292
},
"took": 0,
"timed_out": false
}
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
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
# must not查询
说明
条件组合查询,类似于关系型数据库中的<>
或 !=
关键字。
- URL:http://0.0.0.0:9200/
index_example
/_search
- Method:
POST
- DSL:
select * from index_example where sourceseverity=4 and kpiname="MEM" and sourceciname<>"esp_app02"
- 请求参数:
{
"query": {
"bool": {
"must": [
{
"term": {
"sourceseverity": 4
}
},
{
"term": {
"kpiname": "MEM"
}
}
],
"must_not": {
"term": {
"sourceciname": "esp_app02"
}
}
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
- 响应内容:
{
"_shards": {
"total": 5,
"failed": 0,
"successful": 5,
"skipped": 0
},
"hits": {
"hits": [
{
"_index": "index_example",
"_type": "type_example",
"_source": {
"sourceid": 1005,
"summary": "MEM利用率超过90%",
"severity": 1,
"sourceeventid": "366d8cc1d9742f57",
"sourceseverity": 4,
"lastoccurrence": "2020-11-05 10:03:13",
"sourceciname": "esp_app01",
"kpiname": "MEM",
"citype": "1005",
"status": 1
},
"_id": "S78B-nUBAdDIB8EgHYMd",
"_score": 1.1335313
},
{
"_index": "index_example",
"_type": "type_example",
"_source": {
"sourceid": 2002,
"summary": "MEM更新",
"severity": 2,
"sourceeventid": "200220022002",
"sourceseverity": 4,
"lastoccurrence": "2020-2-20 10:03:13",
"sourceciname": "update",
"kpiname": "MEM",
"citype": "2002",
"status": 1
},
"_id": "TL8B-nUBAdDIB8EgeoNG",
"_score": 1.1335313
}
],
"total": 2,
"max_score": 1.1335313
},
"took": 0,
"timed_out": false
}
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
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
# 更新全部字段
注意
文档更新必须知道文档的_id
,只有与库中的_id
相同才会执行更新操作。
- URL:http://0.0.0.0:9200/
index_example
/type_example
/_id
- Method:
POST
- 请求参数:
{
"sourceid": 2002,
"summary": "MEM更新",
"severity": 2,
"citype": "2002",
"sourceeventid": "200220022002",
"sourceseverity": 2,
"lastoccurrence": "2020-2-20 10:03:13",
"sourceciname": "update",
"kpiname": "MEM",
"status": 1
}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
- 响应内容:
{
"result": "updated",
"_shards": {
"total": 2,
"failed": 0,
"successful": 1
},
"_seq_no": 3,
"_index": "index_example",
"_type": "type_example",
"_id": "TL8B-nUBAdDIB8EgeoNG",
"_version": 2,
"_primary_term": 1
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
# 更新单个字段
- URL:http://0.0.0.0:9200/
index_example
/type_example
/_id
/_update
- Method:
POST
- DSL:
update index_example set summary=1003 where _id="Sr8A-nUBAdDIB8Eg1YOp"
- 请求参数:
{
"doc": {
"summary": "根据id局部更新成功"
}
}
1
2
3
4
5
2
3
4
5
- 响应参数:
{
"result": "updated",
"_shards": {
"total": 2,
"failed": 0,
"successful": 1
},
"_seq_no": 3,
"_index": "index_example",
"_type": "type_example",
"_id": "Sr8A-nUBAdDIB8Eg1YOp",
"_version": 2,
"_primary_term": 1
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
# 批量更新
- URL:http://0.0.0.0:9200/
index_example
/_update_by_query
- Method:
POST
- DSL:
update index_example set sourceseverity=4
- 请求参数:
{
"script": {
"source": "ctx._source['sourceseverity']=4"
},
"query": {
"match_all": {}
}
}
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
- 响应内容:
{
"took": 67,
"throttled_millis": 0,
"failures": [],
"version_conflicts": 0,
"timed_out": false,
"batches": 1,
"retries": {
"search": 0,
"bulk": 0
},
"total": 7,
"deleted": 0,
"noops": 0,
"requests_per_second": -1,
"throttled_until_millis": 0,
"updated": 7
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 删除单条数据
- URL:http://0.0.0.0:9200/
index_example
/doc
/_id
- Method:
DELETE
- 请求参数:无请求参数
- 响应参数:
{
"result": "deleted",
"_shards": {
"total": 2,
"failed": 0,
"successful": 1
},
"_seq_no": 8,
"_index": "index_example",
"_type": "type_example",
"_id": "1",
"_version": 3,
"_primary_term": 1
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
# 批量删除数据
- URL:http://0.0.0.0:9200/
index_example
/_delete_by_query
- Method:
POST
- DSL:
delete from index_example where sourceseverity=2
- 请求参数:
{
"query": {
"term": {
"sourceseverity": 2
}
}
}
1
2
3
4
5
6
7
2
3
4
5
6
7
- 响应内容:
{
"took": 20,
"batches": 1,
"retries": {
"search": 0,
"bulk": 0
},
"throttled_millis": 0,
"total": 1,
"deleted": 1,
"noops": 0,
"requests_per_second": -1,
"failures": [],
"version_conflicts": 0,
"throttled_until_millis": 0,
"timed_out": false
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 清空索引数据
- URL:http://0.0.0.0:9200/
index_example
/_delete_by_query
- Method:
POST
- DSL:
delete from index_example
- 请求参数:
{
"query": {
"match_all": {}
}
}
1
2
3
4
5
2
3
4
5
- 响应内容:
{
"took": 18,
"batches": 1,
"retries": {
"search": 0,
"bulk": 0
},
"throttled_millis": 0,
"total": 6,
"deleted": 6,
"noops": 0,
"requests_per_second": -1,
"failures": [],
"version_conflicts": 0,
"throttled_until_millis": 0,
"timed_out": false
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17