forked from orangejulius/elasticsearch-bash-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcount_types.sh
38 lines (32 loc) · 981 Bytes
/
count_types.sh
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
#!/bin/bash
set -euo pipefail
cluster_url="${cluster_url:-http://localhost:9200}"
index_name="${index_name:-pelias}"
# query for all source values with an aggregation
# this requires fielddata to be loaded, which takes a bit of memory
curl -s -XPOST "$cluster_url/$index_name/_search?size=0" \
-H 'Content-Type: application/json' \
-d '{
"track_total_hits": true,
"aggs" : {
"source_count" : { "terms" : { "field" : "source" } }
}
}'
# query for all layer values with an aggregation
# this requires fielddata to be loaded, which takes a bit of memory
curl -s -XPOST "$cluster_url/$index_name/_search?size=0" \
-H 'Content-Type: application/json' \
-d '{
"track_total_hits": true,
"aggs" : {
"layer_count" : { "terms" : { "field" : "layer", "size": 20 } }
}
}'
# example of how to query for one layer with a search
#curl -XPOST "$cluster_url/$index_name/_search?size=0" -d '{
#"query" : {
#"term": {
#"layer": "country"
#}
#}
#}'