0

I am using the _cat API of elasticsearch to get the various details of my elasticsearch cluster.

https://www.elastic.co/guide/en/elasticsearch/reference/current/cat.html

What I want is the ability to filter the response which I can't see in the documentation, for example output of _cat/node?v give the node.role which tells whether a node is data or master or ingest node and I want a way to filter the only master and data node in the response.

1 Answers1

1

You can use GET /_cat/master instead of _cat/nodes?v to get the master node. Otherwise, you can use the /_nodes/data:true to get only data nodes

GET /_nodes/data:true
GET /_nodes/ingest:true
GET /_nodes/master:true
A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103
  • 1
    Note that you can also mix and match those filters, e.g. to get only data nodes that are not also master eligible: `GET /_nodes/data:true,master:false` – Val Jul 01 '20 at 13:09
  • @Val I was aware of nodes api but its very verbose hence want to filter the _cat/nodes API but this filter pattern doesnt work there :( –  Jul 02 '20 at 03:01
  • @java-dev then probably a combination of `_cat` + `jq` can do the trick: See this https://stackoverflow.com/a/57727356/4604579 – Val Jul 02 '20 at 03:27
  • @java-dev Also using the `_nodes` API you still have the `filter_path` attribute to filter out unneeded data and only get what you want – Val Jul 02 '20 at 03:28
  • @Val I am using 1.x version and just did a quick search on `filter_path` and seems it not availabke even in 6.X :( –  Jul 02 '20 at 03:34
  • @Val JQ I can use but I prefer hitting the api in browser and postman so that I can share it with everybody and they dont hv to install JQ and use the relatively difficult `Jq` –  Jul 02 '20 at 03:35
  • @java-dev of course filter_path was there, even in 1.x: https://www.elastic.co/guide/en/elasticsearch/reference/1.7/common-options.html#_response_filtering – Val Jul 02 '20 at 03:35
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/217055/discussion-between-java-dev-and-val). –  Jul 02 '20 at 03:38