Skip to content

Instantly share code, notes, and snippets.

@jpparis-orange
Last active October 16, 2017 06:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpparis-orange/e79dbfae1cba54799b1476fb4ddfed93 to your computer and use it in GitHub Desktop.
Save jpparis-orange/e79dbfae1cba54799b1476fb4ddfed93 to your computer and use it in GitHub Desktop.
normalize kibana4 save files

When you want to put kibana 4 export.json under git, you'll see that the file changes even if you did not touch searches, vizs or dashboards. The script below uses jq to keep kibana 4 objects (and object keys) in a constant order. Thus, no diffs if you left your kiaban untouched

#! /bin/bash
if [ -z "$1" ]
then
echo "*** Missing file argument" >&2
exit 1
fi
echo "--- Copying to '$1.sav'..."
cp $1 $1.sav
echo "--- Normalizing '$1'..."
cat $1.sav | sed -e 's/ "_id":/ "____id":/' | jq --indent 0 '.[]' | sort | \
jq -s -S '[ .[] |
._source.kibanaSavedObjectMeta.searchSourceJSON |= fromjson |
( select(._type == "visualization") | ._source.visState |= fromjson | . ) // .
]' | \
jq '[.[] |
._source.kibanaSavedObjectMeta.searchSourceJSON |= tojson |
( select(._type == "visualization") | ._source.visState |= tojson | . ) // .
]' | \
sed -e 's/ "____id":/ "_id":/' > $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment