GeekIBLi

elasticsearch 查询值前缀不包含某个字符串

2021-07-20

需求 查询IP不是以11.开头的所有文档,然后获取文档访问量前100条

curl -X GET "localhost:9200/yj_visit_data2,yj_visit_data3/_search?pretty" -u elastic:elastic -H 'Content-Type: application/json' -d'

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
{
"query": {
"bool": {
"must_not": [
{
"bool": {
"should": [
{
"prefix": {
"ip": {
"value": "11."
}
}
},
{
"prefix": {
"ip": {
"value": "1."
}
}
}
]
}
}
],
"must": [
{
"range": {
"visitTime": {
"gte": 1577808000000,
"lte": 1609430399000
}
}
}
]
}
},
"aggs": {
"term_article": {
"terms": {
"field": "ip",
"min_doc_count": 20,
"size": 10000
}
}
}
}
'