Skip to content

Instantly share code, notes, and snippets.

@TomonoriSoejima
Last active November 6, 2020 12:31
Show Gist options
  • Save TomonoriSoejima/5e46dedc7fce24422c377228a3cefb5a to your computer and use it in GitHub Desktop.
Save TomonoriSoejima/5e46dedc7fce24422c377228a3cefb5a to your computer and use it in GitHub Desktop.
jq

[ { "health" : "yellow", "status" : "open", "index" : "das", "uuid" : "f_5xYiYlQT2_YsgSYW6hYQ", "pri" : "5", "rep" : "1", "docs.count" : "0", "docs.deleted" : "0", "store.size" : "1.2kb", "pri.store.size" : "1.2kb" }, { "health" : "green", "status" : "open", "index" : ".monitoring-es-6-2020.03.26", "uuid" : "-FSA0A9zReiQzohaSJ2ZDQ", "pri" : "1", "rep" : "0", "docs.count" : "66910", "docs.deleted" : "451", "store.size" : "33.7mb", "pri.store.size" : "33.7mb" }, { "health" : "green", "status" : "open", "index" : ".monitoring-kibana-6-2020.03.26", "uuid" : "AdvXgUjkTbKQh-lSgaLshA", "pri" : "1", "rep" : "0", "docs.count" : "2476", "docs.deleted" : "0", "store.size" : "709kb", "pri.store.size" : "709kb" }, { "health" : "green", "status" : "open", "index" : ".triggered_watches", "uuid" : "mLiH_ltMShiecxsJ4Cy1_A", "pri" : "1", "rep" : "0", "docs.count" : "0", "docs.deleted" : "0", "store.size" : "240kb", "pri.store.size" : "240kb" }, { "health" : "green", "status" : "open", "index" : ".kibana_1", "uuid" : "hKiPM1rXSMKoKIROqhBwGw", "pri" : "1", "rep" : "0", "docs.count" : "5", "docs.deleted" : "1", "store.size" : "27.1kb", "pri.store.size" : "27.1kb" }, { "health" : "green", "status" : "open", "index" : ".monitoring-kibana-6-2020.03.25", "uuid" : "5M-na7PgRICC0usCyPHo8g", "pri" : "1", "rep" : "0", "docs.count" : "660", "docs.deleted" : "0", "store.size" : "226.1kb", "pri.store.size" : "226.1kb" }, { "health" : "green", "status" : "open", "index" : ".monitoring-es-6-2020.03.27", "uuid" : "bsyaByEhQB2gg61FjbzEtA", "pri" : "1", "rep" : "0", "docs.count" : "33803", "docs.deleted" : "396", "store.size" : "17.9mb", "pri.store.size" : "17.9mb" }, { "health" : "yellow", "status" : "open", "index" : "hotel2", "uuid" : "s9UyXGBGTU-yc3PnDdktzA", "pri" : "5", "rep" : "1", "docs.count" : "1", "docs.deleted" : "0", "store.size" : "5kb", "pri.store.size" : "5kb" }, { "health" : "green", "status" : "open", "index" : ".monitoring-es-6-2020.03.25", "uuid" : "zn6U_XG1Q1KLxHHCrzvGRw", "pri" : "1", "rep" : "0", "docs.count" : "15552", "docs.deleted" : "55", "store.size" : "8.4mb", "pri.store.size" : "8.4mb" }, { "health" : "green", "status" : "open", "index" : ".monitoring-alerts-6", "uuid" : "3EAu5C08Qgy07VFrLsNlvQ", "pri" : "1", "rep" : "0", "docs.count" : "2", "docs.deleted" : "0", "store.size" : "19.6kb", "pri.store.size" : "19.6kb" }, { "health" : "green", "status" : "open", "index" : ".monitoring-kibana-6-2020.03.27", "uuid" : "n-zyP03mT_a7N3hedw5Raw", "pri" : "1", "rep" : "0", "docs.count" : "1342", "docs.deleted" : "0", "store.size" : "443.4kb", "pri.store.size" : "443.4kb" }, { "health" : "green", "status" : "open", "index" : ".kibana_task_manager", "uuid" : "-HE8qrjhTSypU6mq9L87Qg", "pri" : "1", "rep" : "0", "docs.count" : "2", "docs.deleted" : "0", "store.size" : "12.5kb", "pri.store.size" : "12.5kb" }, { "health" : "yellow", "status" : "open", "index" : "my_index", "uuid" : "jDsMTgxxRHObqVeena1sWQ", "pri" : "5", "rep" : "1", "docs.count" : "1", "docs.deleted" : "0", "store.size" : "4.4kb", "pri.store.size" : "4.4kb" }, { "health" : "yellow", "status" : "open", "index" : "hello2", "uuid" : "XDL2KOm-QfasQu4EhD8LiA", "pri" : "5", "rep" : "1", "docs.count" : "0", "docs.deleted" : "0", "store.size" : "1.2kb", "pri.store.size" : "1.2kb" }, { "health" : "green", "status" : "open", "index" : ".watcher-history-9-2020.03.27", "uuid" : "Xwy-Q0Y0SRCS_ArjTlx-Rw", "pri" : "1", "rep" : "0", "docs.count" : "1804", "docs.deleted" : "0", "store.size" : "2.3mb", "pri.store.size" : "2.3mb" }, { "health" : "green", "status" : "open", "index" : ".watcher-history-9-2020.03.25", "uuid" : "BfKFdHjCSi6Pd2wBcx9jpw", "pri" : "1", "rep" : "0", "docs.count" : "974", "docs.deleted" : "0", "store.size" : "1.2mb", "pri.store.size" : "1.2mb" }, { "health" : "green", "status" : "open", "index" : ".watcher-history-9-2020.03.26", "uuid" : "vcVYNSRUQiisOZrMwm0NYw", "pri" : "1", "rep" : "0", "docs.count" : "3436", "docs.deleted" : "0", "store.size" : "4.2mb", "pri.store.size" : "4.2mb" }, { "health" : "yellow", "status" : "open", "index" : "hotel", "uuid" : "89iG-j7eTEaMYHMG5jjgGw", "pri" : "1", "rep" : "1", "docs.count" : "25000", "docs.deleted" : "0", "store.size" : "3.7mb", "pri.store.size" : "3.7mb" }, { "health" : "green", "status" : "open", "index" : ".watches", "uuid" : "6nmO44SpRZqxrdvpoHGDLA", "pri" : "1", "rep" : "0", "docs.count" : "6", "docs.deleted" : "0", "store.size" : "805.1kb", "pri.store.size" : "805.1kb" }, { "health" : "yellow", "status" : "open", "index" : "hello", "uuid" : "fA3-znQcTnWSj73MbRNzVQ", "pri" : "5", "rep" : "1", "docs.count" : "1", "docs.deleted" : "0", "store.size" : "4.4kb", "pri.store.size" : "4.4kb" } ]

.[] | {index:.index, docs: .["docs.count"] | tonumber , sa: (.["docs.count"] | tonumber  - 2)}


.[] | {index:.index, docs: .["docs.count"] | tonumber,  del: .["docs.deleted"] | tonumber} | { index: .index, sa: (.docs - .del)}


. | sort_by( .["docs.count"] | tonumber )

# ng
.[] | .index ,  .["docs.count"] |  .["docs.count"]  | sort_by( .["docs.count"] | tonumber )

# ok
. | sort_by( .["docs.count"] | tonumber ) | reverse[] | .index, .["docs.count"]

. | sort_by( .["docs.count"] | tonumber ) | reverse[]

# ok - for select

. | sort_by( .["docs.count"] | tonumber ) | reverse[] | {index: .index, count: (.["docs.count"] | tonumber)} | select ( .count > 454541)
.[] | {index:.index, docs: .count , sa: (.count - .deleted)}


# input 
[
  {
    "health" : "yellow",
    "status" : "open",
    "index" : "das",
    "uuid" : "f_5xYiYlQT2_YsgSYW6hYQ",
    "pri" : "5",
    "rep" : "1",
    "count" : 30,
    "deleted" : 2,
    "store.size" : "1.2kb",
    "pri.store.size" : "1.2kb"
  }
]


# result

{
  "index": "das",
  "docs": 30,
  "sa": 28
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment