Hey! All of the CAT APIs come with this disclaimer:
IMPORTANT: cat APIs are only intended for human consumption using the command line or Kibana console. They are not intended for use by applications.
Is there an alternative API, intended for use by applications, that can return the index name, shard number, shard state, prirep and the node name (not the node ID)?
As far as I can tell, getting all this would require calling multiple APIs (e.g. /_stats and /_nodes) and cross-referencing the node ID, but I would like to call just a single API, if possible, in order to minimise the load on the cluster.
I thought the cluster state API could be the way to go but that has a similar disclaimer:
WARNING: The response is a representation of an internal data structure. Its format is not subject to the same compatibility guarantees as other more stable APIs and may change from version to version. Do not query this API using external monitoring tools. Instead, obtain the information you require using other more stable cluster APIs.
Interesting question, I hope someone answers. I’d always considered the _cat APIs as more aimed at administrators of the elasticsearch system itself, rather than applications/developers.
Out of curiosity, what is your use case where your application needs to know (eg) if a specific shard from a specific index is a replica or a primary shard? What would your application do with that information?
Short answer: no. You need to cross-reference GET _stats and GET _nodes. That’s effectively all that GET _cat/shards does anyway so the load will be the same.
If you really want to trim things down then GET _nodes/_all/info/none?filter_path=nodes.*.name is the most efficient way I can think of to get a mapping from node IDs to node names. You can cache this result too, unless you’re doing something weird that would result in nodes’ names changing (in which case: don’t do that!).
GET _stats is the heavy one but it has many options for cutting out bits you don’t need.
But also yeah what @RainTown said: what are you actually doing with this information? It’s rare to need it at the application level.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.