dwyl / esta

:mag: Simple + Fast ElasticSearch Node.js client. Beginner-friendly defaults & Heroku support :white_check_mark: :rocket:
49 stars 10 forks source link

Count how many records in ES [ _stats ] #31

Closed nelsonic closed 9 years ago

nelsonic commented 9 years ago

http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/cardinality.html

nelsonic commented 9 years ago

_stats does the trick nicely:

curl 127.0.0.1:9200/_stats?pretty

Output:

{
  "_shards" : {
    "total" : 10,
    "successful" : 5,
    "failed" : 0
  },
  "_all" : {
    "primaries" : {
      "docs" : {
        "count" : 1498,
        "deleted" : 1
      },
      "store" : {
        "size_in_bytes" : 7100741,
        "throttle_time_in_millis" : 118
      },
      "indexing" : {
        "index_total" : 4497,
        "index_time_in_millis" : 16857,
        "index_current" : 0,
        "delete_total" : 0,
        "delete_time_in_millis" : 0,
        "delete_current" : 0,
        "noop_update_total" : 0,
        "is_throttled" : false,
        "throttle_time_in_millis" : 0
      },
      "get" : {
        "total" : 2,
        "time_in_millis" : 1,
        "exists_total" : 2,
        "exists_time_in_millis" : 1,
        "missing_total" : 0,
        "missing_time_in_millis" : 0,
        "current" : 0
      },
      "search" : {
        "open_contexts" : 5,
        "query_total" : 35,
        "query_time_in_millis" : 234,
        "query_current" : 0,
        "fetch_total" : 20,
        "fetch_time_in_millis" : 71,
        "fetch_current" : 0
      },
      "merges" : {
        "current" : 0,
        "current_docs" : 0,
        "current_size_in_bytes" : 0,
        "total" : 4,
        "total_time_in_millis" : 18843,
        "total_docs" : 1199,
        "total_size_in_bytes" : 6675287
      },
      "refresh" : {
        "total" : 126,
        "total_time_in_millis" : 17311
      },
      "flush" : {
        "total" : 10,
        "total_time_in_millis" : 138
      },
      "warmer" : {
        "current" : 0,
        "total" : 248,
        "total_time_in_millis" : 387
      },
      "filter_cache" : {
        "memory_size_in_bytes" : 1640,
        "evictions" : 0
      },
      "id_cache" : {
        "memory_size_in_bytes" : 0
      },
      "fielddata" : {
        "memory_size_in_bytes" : 0,
        "evictions" : 0
      },
      "percolate" : {
        "total" : 0,
        "time_in_millis" : 0,
        "current" : 0,
        "memory_size_in_bytes" : -1,
        "memory_size" : "-1b",
        "queries" : 0
      },
      "completion" : {
        "size_in_bytes" : 0
      },
      "segments" : {
        "count" : 28,
        "memory_in_bytes" : 6210032,
        "index_writer_memory_in_bytes" : 0,
        "index_writer_max_memory_in_bytes" : 2560000,
        "version_map_memory_in_bytes" : 0,
        "fixed_bit_set_memory_in_bytes" : 0
      },
      "translog" : {
        "operations" : 0,
        "size_in_bytes" : 17
      },
      "suggest" : {
        "total" : 0,
        "time_in_millis" : 0,
        "current" : 0
      },
      "query_cache" : {
        "memory_size_in_bytes" : 0,
        "evictions" : 0,
        "hit_count" : 0,
        "miss_count" : 0
      }
    },
    "total" : {
      "docs" : {
        "count" : 1498,
        "deleted" : 1
      },
      "store" : {
        "size_in_bytes" : 7100741,
        "throttle_time_in_millis" : 118
      },
      "indexing" : {
        "index_total" : 4497,
        "index_time_in_millis" : 16857,
        "index_current" : 0,
        "delete_total" : 0,
        "delete_time_in_millis" : 0,
        "delete_current" : 0,
        "noop_update_total" : 0,
        "is_throttled" : false,
        "throttle_time_in_millis" : 0
      },
      "get" : {
        "total" : 2,
        "time_in_millis" : 1,
        "exists_total" : 2,
        "exists_time_in_millis" : 1,
        "missing_total" : 0,
        "missing_time_in_millis" : 0,
        "current" : 0
      },
      "search" : {
        "open_contexts" : 5,
        "query_total" : 35,
        "query_time_in_millis" : 234,
        "query_current" : 0,
        "fetch_total" : 20,
        "fetch_time_in_millis" : 71,
        "fetch_current" : 0
      },
      "merges" : {
        "current" : 0,
        "current_docs" : 0,
        "current_size_in_bytes" : 0,
        "total" : 4,
        "total_time_in_millis" : 18843,
        "total_docs" : 1199,
        "total_size_in_bytes" : 6675287
      },
      "refresh" : {
        "total" : 126,
        "total_time_in_millis" : 17311
      },
      "flush" : {
        "total" : 10,
        "total_time_in_millis" : 138
      },
      "warmer" : {
        "current" : 0,
        "total" : 248,
        "total_time_in_millis" : 387
      },
      "filter_cache" : {
        "memory_size_in_bytes" : 1640,
        "evictions" : 0
      },
      "id_cache" : {
        "memory_size_in_bytes" : 0
      },
      "fielddata" : {
        "memory_size_in_bytes" : 0,
        "evictions" : 0
      },
      "percolate" : {
        "total" : 0,
        "time_in_millis" : 0,
        "current" : 0,
        "memory_size_in_bytes" : -1,
        "memory_size" : "-1b",
        "queries" : 0
      },
      "completion" : {
        "size_in_bytes" : 0
      },
      "segments" : {
        "count" : 28,
        "memory_in_bytes" : 6210032,
        "index_writer_memory_in_bytes" : 0,
        "index_writer_max_memory_in_bytes" : 2560000,
        "version_map_memory_in_bytes" : 0,
        "fixed_bit_set_memory_in_bytes" : 0
      },
      "translog" : {
        "operations" : 0,
        "size_in_bytes" : 17
      },
      "suggest" : {
        "total" : 0,
        "time_in_millis" : 0,
        "current" : 0
      },
      "query_cache" : {
        "memory_size_in_bytes" : 0,
        "evictions" : 0,
        "hit_count" : 0,
        "miss_count" : 0
      }
    }
  },
  "indices" : {
    "twitter" : {
      "primaries" : {
        "docs" : {
          "count" : 1498,
          "deleted" : 1
        },
        "store" : {
          "size_in_bytes" : 7100741,
          "throttle_time_in_millis" : 118
        },
        "indexing" : {
          "index_total" : 4497,
          "index_time_in_millis" : 16857,
          "index_current" : 0,
          "delete_total" : 0,
          "delete_time_in_millis" : 0,
          "delete_current" : 0,
          "noop_update_total" : 0,
          "is_throttled" : false,
          "throttle_time_in_millis" : 0
        },
        "get" : {
          "total" : 2,
          "time_in_millis" : 1,
          "exists_total" : 2,
          "exists_time_in_millis" : 1,
          "missing_total" : 0,
          "missing_time_in_millis" : 0,
          "current" : 0
        },
        "search" : {
          "open_contexts" : 5,
          "query_total" : 35,
          "query_time_in_millis" : 234,
          "query_current" : 0,
          "fetch_total" : 20,
          "fetch_time_in_millis" : 71,
          "fetch_current" : 0
        },
        "merges" : {
          "current" : 0,
          "current_docs" : 0,
          "current_size_in_bytes" : 0,
          "total" : 4,
          "total_time_in_millis" : 18843,
          "total_docs" : 1199,
          "total_size_in_bytes" : 6675287
        },
        "refresh" : {
          "total" : 126,
          "total_time_in_millis" : 17311
        },
        "flush" : {
          "total" : 10,
          "total_time_in_millis" : 138
        },
        "warmer" : {
          "current" : 0,
          "total" : 248,
          "total_time_in_millis" : 387
        },
        "filter_cache" : {
          "memory_size_in_bytes" : 1640,
          "evictions" : 0
        },
        "id_cache" : {
          "memory_size_in_bytes" : 0
        },
        "fielddata" : {
          "memory_size_in_bytes" : 0,
          "evictions" : 0
        },
        "percolate" : {
          "total" : 0,
          "time_in_millis" : 0,
          "current" : 0,
          "memory_size_in_bytes" : -1,
          "memory_size" : "-1b",
          "queries" : 0
        },
        "completion" : {
          "size_in_bytes" : 0
        },
        "segments" : {
          "count" : 28,
          "memory_in_bytes" : 6210032,
          "index_writer_memory_in_bytes" : 0,
          "index_writer_max_memory_in_bytes" : 2560000,
          "version_map_memory_in_bytes" : 0,
          "fixed_bit_set_memory_in_bytes" : 0
        },
        "translog" : {
          "operations" : 0,
          "size_in_bytes" : 17
        },
        "suggest" : {
          "total" : 0,
          "time_in_millis" : 0,
          "current" : 0
        },
        "query_cache" : {
          "memory_size_in_bytes" : 0,
          "evictions" : 0,
          "hit_count" : 0,
          "miss_count" : 0
        }
      },
      "total" : {
        "docs" : {
          "count" : 1498,
          "deleted" : 1
        },
        "store" : {
          "size_in_bytes" : 7100741,
          "throttle_time_in_millis" : 118
        },
        "indexing" : {
          "index_total" : 4497,
          "index_time_in_millis" : 16857,
          "index_current" : 0,
          "delete_total" : 0,
          "delete_time_in_millis" : 0,
          "delete_current" : 0,
          "noop_update_total" : 0,
          "is_throttled" : false,
          "throttle_time_in_millis" : 0
        },
        "get" : {
          "total" : 2,
          "time_in_millis" : 1,
          "exists_total" : 2,
          "exists_time_in_millis" : 1,
          "missing_total" : 0,
          "missing_time_in_millis" : 0,
          "current" : 0
        },
        "search" : {
          "open_contexts" : 5,
          "query_total" : 35,
          "query_time_in_millis" : 234,
          "query_current" : 0,
          "fetch_total" : 20,
          "fetch_time_in_millis" : 71,
          "fetch_current" : 0
        },
        "merges" : {
          "current" : 0,
          "current_docs" : 0,
          "current_size_in_bytes" : 0,
          "total" : 4,
          "total_time_in_millis" : 18843,
          "total_docs" : 1199,
          "total_size_in_bytes" : 6675287
        },
        "refresh" : {
          "total" : 126,
          "total_time_in_millis" : 17311
        },
        "flush" : {
          "total" : 10,
          "total_time_in_millis" : 138
        },
        "warmer" : {
          "current" : 0,
          "total" : 248,
          "total_time_in_millis" : 387
        },
        "filter_cache" : {
          "memory_size_in_bytes" : 1640,
          "evictions" : 0
        },
        "id_cache" : {
          "memory_size_in_bytes" : 0
        },
        "fielddata" : {
          "memory_size_in_bytes" : 0,
          "evictions" : 0
        },
        "percolate" : {
          "total" : 0,
          "time_in_millis" : 0,
          "current" : 0,
          "memory_size_in_bytes" : -1,
          "memory_size" : "-1b",
          "queries" : 0
        },
        "completion" : {
          "size_in_bytes" : 0
        },
        "segments" : {
          "count" : 28,
          "memory_in_bytes" : 6210032,
          "index_writer_memory_in_bytes" : 0,
          "index_writer_max_memory_in_bytes" : 2560000,
          "version_map_memory_in_bytes" : 0,
          "fixed_bit_set_memory_in_bytes" : 0
        },
        "translog" : {
          "operations" : 0,
          "size_in_bytes" : 17
        },
        "suggest" : {
          "total" : 0,
          "time_in_millis" : 0,
          "current" : 0
        },
        "query_cache" : {
          "memory_size_in_bytes" : 0,
          "evictions" : 0,
          "hit_count" : 0,
          "miss_count" : 0
        }
      }
    }
  }
}
nelsonic commented 9 years ago

Decided to expose the stats method for later. ;-)