Skip to content

Instantly share code, notes, and snippets.

@ebuildy
Created June 20, 2023 15:30
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 ebuildy/98022b0bf441795910e8f072c33f620b to your computer and use it in GitHub Desktop.
Save ebuildy/98022b0bf441795910e8f072c33f620b to your computer and use it in GitHub Desktop.
Compare elasticsearch indices mapping
#!/bin/bash
##
# Requirements: jq, jd, curl
# Variables:
# - ES_AUTH --> elasticsearch auth
##
alias es_curl="curl -H "application/json" -u $ES_AUTH"
export WORKDIR=/tmp/index-compare
mkdir -p $WORKDIR
rm -rf $WORKDIR/*
# Elasticsearch server details
ES_HOST="localhost"
ES_PORT="9200"
# Indices to compare
INDEX1=".ds-metricbeat-8.8.0-argocd-2023.06.07-000003"
INDEX2=".ds-metricbeat-8.8.0-*"
function downloadIndex() {
content=$(es_curl -s -XGET "http://${ES_HOST}:${ES_PORT}/$1/_mapping")
data=$(jq -r 'to_entries[0].value.mappings.properties' <<< "${content}")
echo "${data}" > "$WORKDIR/$1.json"
}
downloadIndex $INDEX1
INDICES=$(es_curl -s -XGET "http://${ES_HOST}:${ES_PORT}/_cat/indices/$INDEX2?h=index")
for INDEX2 in $INDICES; do
echo " + diff $INDEX1 <-> $INDEX2"
downloadIndex $INDEX2
jd -set $WORKDIR/$INDEX1.json $WORKDIR/$INDEX2.json
echo ""
echo ""
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment