基本搜索

1
2
3
4
5
6
7
8
9
10
11
12
13
{
"query": {
"bool": {
"must": [
{
"match_all": {}
}
]
}
},
"from": 0,
"size": 1
}

Group BY

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
{
"query": {
"bool": {
"must": [
{
"match_all": {}
}
]
}
},
"from": 0,
"size": 0,
"aggregations": {
"mid": {
"aggregations": {
"terminal": {
"terms": {
"field": "terminal",
"size": 0
}
}
},
"terms": {
"field": "mid",
"size": "1"
}
}
}
}

Distinct Count

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
"query": {
"bool": {
"must": [
{
"match_all": {}
}
]
}
},
"from": 0,
"size": 0,
"aggregations": {
"COUNT(distinct (mid))": {
"cardinality": {
"field": "(mid)"
}
}
}
}

全文搜索

1
2
3
4
5
{
"query" : {
"query_string" : {"query" : "name:rcx"}
}
}

match查询

1
2
3
4
5
6
7
{
"query": {
"match": {
"title": "crime and punishment"
}
}
}

通配符查询

1
2
3
4
5
6
7
{
"query": {
"wildcard": {
"title": "cr?me"
}
}
}

范围查询

1
2
3
4
5
6
7
8
9
10
{
"query": {
"range": {
"year": {
"gte" :1890,
"lte":1900
}
}
}
}

正则表达式查询

1
2
3
4
5
6
7
8
9
10
{
"query": {
"regexp": {
"title": {
"value" :"cr.m[ae]",
"boost":10.0
}
}
}
}

布尔查询

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
"query": {
"bool": {
"must": {
"term": {
"title": "crime"
}
},
"should": {
"range": {
"year": {
"from": 1900,
"to": 2000
}
}
},
"must_not": {
"term": {
"otitle": "nothing"
}
}
}
}
}

更新

1
2
3
4
5
6
index111/_doc/_30016/_update
{
"doc": {
"follow_status": "following"
}
}

refresh