Skip to content

Instantly share code, notes, and snippets.

@markwalkom
Last active May 21, 2016 09:27
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 markwalkom/41157a92362a4248824178566a7f1464 to your computer and use it in GitHub Desktop.
Save markwalkom/41157a92362a4248824178566a7f1464 to your computer and use it in GitHub Desktop.
jq tips

Elasticsearch

Sum number of docs in a cluster

cat nodes_stats.json|jq '.nodes[].indices.docs.count'|awk '{s+=$0} END {print s}'

Sum total store size

cat nodes_stats.json|jq '.nodes[].indices.store.size_in_bytes'|awk '{s+=$0} END {print s}'

Working with the swapi data

Get a list of planets + key for translate lookup

cat people.json | jq -r '.[]|"\"\(.pk)\"" + ": " + "\"\(.fields.name)\""'

Flatten

jq -c -M 'map(.fields + with_entries(select(.key != "fields")))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment