Created
August 14, 2015 20:18
-
-
Save netj/b29936125f05e1c63051 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
#!/usr/bin/env bash | |
# A script to create a Elasticsearch playground with GVim | |
set -eu | |
mkdir -p esplay.d | |
cd esplay.d | |
# prepare a query running script | |
echo >_search.sh '#!/usr/bin/env bash | |
set -eu | |
set -o pipefail | |
cd "$(dirname "$0")" | |
url=$(cat elasticsearch.url) | |
id=$(date +%Y%m%d/%H%M%S.%N) | |
mkdir -p "$id" | |
cp -f q.cson "$id"/ | |
( | |
cd "$id" | |
set -x | |
cson2json <q.cson >q.json | |
curl -vsSL $url/_search?pretty -d @q.json -o _search.json | |
) 2>&1 | | |
tee "$id"/_search.log | |
ln -sfnv "$id" LATEST | |
' | |
chmod +x _search.sh | |
# symlinks | |
ln -sfnv LATEST/q.json | |
ln -sfnv LATEST/_search.json | |
# URL | |
[[ -e url ]] || { | |
: ${ELASTICSEARCH_BASEURL:?must be set to a valid URL} | |
echo "$ELASTICSEARCH_BASEURL" >elasticsearch.url | |
} | |
# a template query DSL in CSON | |
[[ -e q.cson ]] || | |
echo >q.cson '# Query Elasticsearch in CSON (https://github.com/bevry/cson#readme) | |
query: | |
query_string: | |
query: "foo" | |
filter: | |
{} | |
aggs: | |
{} | |
highlight: | |
{} | |
' | |
# launch GVim with handy key mappings | |
gvim _search.json \ | |
+'setl autoread' \ | |
+'vsplit q.cson' \ | |
+'1split elasticsearch.url' \ | |
+'norm x23p' \ | |
+'set makeprg=./_search.sh' \ | |
+'set efm=%+E<\ HTTP/1.1\ %*[^2]%*\\d\ %m' \ | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment