/
scroll_test.sh
executable file
·48 lines (47 loc) · 1.26 KB
/
scroll_test.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
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
#
# Example of using scroll with sort
#
set -e
USERNAME=elastic
PASSWORD=password
AUTH="-u $USERNAME:$PASSWORD"
ES=http://localhost:9200
curl $AUTH -XDELETE "$ES/test?allow_no_indices=true&pretty=true"
curl $AUTH -XPUT "$ES/test?pretty=true" -H 'Content-Type: application/json' -d '{
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 0
}
},
"mappings": {
"properties": {
"foo": {
"type": "integer"
}
}
}
}'
echo
echo Indexing....
for n in {1..2000}; do
curl $AUTH -s -XPOST "$ES/test/_doc" -H 'Content-Type: application/json' -d "{\"foo\":$RANDOM}" > /dev/null;
done;
curl $AUTH -XPOST "$ES/test/_refresh?pretty"
echo Done
SCROLL_ID=$(curl $AUTH -s -XGET "$ES/test/_search?pretty&scroll=1m" -H 'Content-Type: application/json' -d '{
"size": 100,
"aggs": {
"avg_foo": { "avg": { "field": "foo" } }
},
"sort" : [
{ "foo" : "asc"}
]
}' | tee /dev/tty | jq "._scroll_id")
for n in {1..20}; do
SCROLL_ID=$(curl -s $AUTH -XGET "$ES/_search/scroll?pretty" -H 'Content-Type: application/json' -d '{
"scroll" : "1m",
"scroll_id" : '$SCROLL_ID'
}' | tee /dev/tty | jq "._scroll_id")
done;