Created
October 16, 2015 13:32
-
-
Save nik9000/bf39d573b08722fa3629 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
set -o pipefail | |
REFRESH_INTERVAL=${1-1s} | |
# Updates test/test/$1 and sets foo=$2 and returns the updated version | |
put() { | |
local id=$1 | |
local foo=$2 | |
curl -s -XPUT localhost:9200/test/test/$id?pretty -d '{"foo":"'$foo'"}' | tee -a out | grep _version | cut -d' ' -f 5 | cut -d',' -f 1 | |
} | |
non_realtime_get() { | |
curl -s 'localhost:9200/test/test/'$1'?realtime=false&fields=false&pretty' | tee -a out | |
} | |
echo "This demonstrates non-realtime get as a way to check for visibility after updates." | |
echo "Every '.' after this one is a 100ms sleep." | |
echo -n "Rebuilding the index--->" | tee out | |
curl -s -XDELETE localhost:9200/test >> out | |
curl -s -XPUT localhost:9200/test -d '{ | |
"index": { | |
"refresh_interval": "'$REFRESH_INTERVAL'" | |
} | |
}' >> out | |
echo "done (refresh_interval is $REFRESH_INTERVAL)" | tee -a out | |
echo -n "Creating---->" | tee -a out; echo >> out | |
version=$(put 1 bar) | |
echo -n "waiting for refresh" | tee -a out; echo >> out | |
# This should be >= not string == but this demonstrates it | |
until non_realtime_get 1 | grep '"_version" : '$version > /dev/null; do | |
echo -n . | tee -a out | |
sleep .1 | |
done | |
echo "refreshed" | tee -a out | |
echo -n "Updating---->" | tee -a out; echo >> out | |
version=$(put 1 baz) | |
echo -n "waiting for refresh" | tee -a out; echo >> out | |
# This should be >= not string == but this demonstrates it | |
until non_realtime_get 1 | grep '"_version" : '$version > /dev/null; do | |
echo -n . | tee -a out | |
sleep .1 | |
done | |
echo "refreshed" | tee -a out | |
echo -n "Deleting---->" | tee -a out; echo >> out | |
curl -s -XDELETE localhost:9200/test/test/1?pretty >> out | |
echo -n "waiting for refresh" | tee -a out; echo >> out | |
until non_realtime_get 1 | grep '"found" : false' > /dev/null; do | |
echo -n . | tee -a out | |
sleep .1 | |
done | |
echo "refreshed" | tee -a out | |
echo -n "Recreating-->" | tee -a out; echo >> out | |
version=$(put 1 bar) # Sometimes this version will be 1. | |
echo -n "waiting for refresh" | tee -a out; echo >> out | |
# This should be >= not string == but this demonstrates it | |
until non_realtime_get 1 | grep '"_version" : '$version > /dev/null; do | |
echo -n . | tee -a out | |
sleep .1 | |
done | |
echo "refreshed (version was $version)" | tee -a out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment