-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathttl.sh
executable file
·50 lines (48 loc) · 1.28 KB
/
ttl.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
49
#!/bin/bash
#
# Demonstrates the use of _ttl
#
#
# Change the ttl interval on the cluster to make this example to run faster
# **** THIS IS CLUSTER-WIDE SETTING. DON'T USE IN PRODUCTION ****
#
curl -XPUT localhost:9200/_cluster/settings -d '{
"transient": {
"indices.ttl.interval": "1s"
}
}'
echo
curl -XDELETE localhost:9200/test
echo
curl -XPUT localhost:9200/test -d '{
"settings": {
"index.number_of_shards": 1,
"index.number_of_replicas": 0
},
"mappings": {
"doc": {
"_ttl" : { "enabled" : true },
"properties": {
"title": { "type": "string" }
}
}
}
}'
curl -XPUT localhost:9200/test/doc/1 -d '{"title": "never expire"}'
curl -XPUT localhost:9200/test/doc/2 -d '{"title": "expire in 5 sec", "_ttl": "5s"}'
curl -XPUT localhost:9200/test/doc/3 -d '{"title": "expire in 15 sec", "_ttl": "15s"}'
echo
curl -XPOST localhost:9200/test/_refresh
echo
echo "Search should return all"
curl -XGET "localhost:9200/test/_search?pretty=true"
echo
echo "Sleeping 6 sec"
sleep 6
echo "Search should return 2 records"
curl -XGET "localhost:9200/test/_search?pretty=true"
echo
echo "Sleeping 10 sec"
sleep 10
echo "Search should return 1 record"
curl -XGET "localhost:9200/test/_search?pretty=true"