Node roles in Elasticsearch 2.x

What's a reliable way to retrieve the roles of an Elasticsearch node (master, data, client) with Elasticsearch 2.x?

It seems that the attributes field in the Nodes Info API isn't available all the time:

$ curl http://127.0.0.1:9200/?pretty
{
  "name" : "King Bedlam",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "2.4.0",
    "build_hash" : "ce9f0c7394dee074091dd1bc4e9469251181fc55",
    "build_timestamp" : "2016-08-29T09:14:17Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.2"
  },
  "tagline" : "You Know, for Search"
}
$ curl -s http://127.0.0.1:9200/_nodes?pretty | jq '.nodes | .[] | [.attributes]'
[
  {
    "client": "true",
    "data": "false",
    "master": "false"
  }
]
[
  null
]

The full output of the Nodes Info API is as follows (slightly shortened to fit the character limits):

$ curl -s http://127.0.0.1:9200/_nodes?pretty
{
  "cluster_name" : "elasticsearch",
  "nodes" : {
    "DeehriT-TxqB_DeZBnuNMA" : {
      "name" : "custom-client-node",
      "transport_address" : "127.0.0.1:9350",
      "host" : "127.0.0.1",
      "ip" : "127.0.0.1",
      "version" : "2.4.4",
      "build" : "fcbb46d",
      "http_address" : "127.0.0.1:9201",
      "attributes" : {
        "client" : "true",
        "data" : "false",
        "master" : "false"
      },
      "settings" : {
        "cluster" : {
          "name" : "elasticsearch"
        },
        "node" : {
          "name" : "custom-client-node",
          "client" : "true",
          "data" : "false",
          "master" : "false"
        },
        "path" : {
          "data" : "data/elasticsearch",
          "logs" : "data/elasticsearch/logs",
          "home" : "data/elasticsearch"
        },
        "discovery" : {
          "zen" : {
            "ping" : {
              "unicast" : {
                "hosts" : [ "127.0.0.1:9300" ]
              }
            }
          },
          "initial_state_timeout" : "3s"
        },
        "name" : "custom-client-node",
        "action" : {
          "auto_create_index" : "false"
        },
        "client" : {
          "type" : "node"
        },
        "http" : {
          "enabled" : "true"
        },
        "transport" : {
          "tcp" : {
            "port" : "9350"
          }
        }
      },
      "os" : {
        "refresh_interval_in_millis" : 1000,
        "name" : "Mac OS X",
        "arch" : "x86_64",
        "version" : "10.12.4",
        "available_processors" : 8,
        "allocated_processors" : 8
      },
      "process" : {
        "refresh_interval_in_millis" : 1000,
        "id" : 20772,
        "mlockall" : false
      },
      "jvm" : {
        "pid" : 20772,
        "version" : "1.8.0_121",
        "vm_name" : "Java HotSpot(TM) 64-Bit Server VM",
        "vm_version" : "25.121-b13",
        "vm_vendor" : "Oracle Corporation",
        "start_time_in_millis" : 1492595873725,
        "mem" : {
          "heap_init_in_bytes" : 268435456,
          "heap_max_in_bytes" : 3817865216,
          "non_heap_init_in_bytes" : 2555904,
          "non_heap_max_in_bytes" : 0,
          "direct_max_in_bytes" : 3817865216
        },
        "gc_collectors" : [ "PS Scavenge", "PS MarkSweep" ],
        "memory_pools" : [ "Code Cache", "Metaspace", "Compressed Class Space", "PS Eden Space", "PS Survivor Space", "PS Old Gen" ],
        "using_compressed_ordinary_object_pointers" : "true"
      },
      "thread_pool" : { … },
      "transport" : {
        "bound_address" : [ "127.0.0.1:9350" ],
        "publish_address" : "127.0.0.1:9350",
        "profiles" : { }
      },
      "http" : {
        "bound_address" : [ "127.0.0.1:9201" ],
        "publish_address" : "127.0.0.1:9201",
        "max_content_length_in_bytes" : 104857600
      },
      "plugins" : [ ],
      "modules" : [ ]
    },
    "0P3xXxKKSF6rKryL6pdM6Q" : {
      "name" : "King Bedlam",
      "transport_address" : "127.0.0.1:9300",
      "host" : "127.0.0.1",
      "ip" : "127.0.0.1",
      "version" : "2.4.0",
      "build" : "ce9f0c7",
      "http_address" : "127.0.0.1:9200",
      "settings" : {
        "name" : "King Bedlam",
        "client" : {
          "type" : "node"
        },
        "cluster" : {
          "name" : "elasticsearch"
        },
        "path" : {
          "logs" : "elasticsearch-2.4.0/logs",
          "home" : "elasticsearch-2.4.0"
        },
        "config" : {
          "ignore_system_properties" : "true"
        },
        "network" : {
          "host" : "127.0.0.1"
        }
      },
      "os" : {
        "refresh_interval_in_millis" : 1000,
        "name" : "Mac OS X",
        "arch" : "x86_64",
        "version" : "10.12.4",
        "available_processors" : 8,
        "allocated_processors" : 8
      },
      "process" : {
        "refresh_interval_in_millis" : 1000,
        "id" : 20651,
        "mlockall" : false
      },
      "jvm" : {
        "pid" : 20651,
        "version" : "1.8.0_121",
        "vm_name" : "Java HotSpot(TM) 64-Bit Server VM",
        "vm_version" : "25.121-b13",
        "vm_vendor" : "Oracle Corporation",
        "start_time_in_millis" : 1492594873945,
        "mem" : {
          "heap_init_in_bytes" : 268435456,
          "heap_max_in_bytes" : 1037959168,
          "non_heap_init_in_bytes" : 2555904,
          "non_heap_max_in_bytes" : 0,
          "direct_max_in_bytes" : 1037959168
        },
        "gc_collectors" : [ "ParNew", "ConcurrentMarkSweep" ],
        "memory_pools" : [ "Code Cache", "Metaspace", "Compressed Class Space", "Par Eden Space", "Par Survivor Space", "CMS Old Gen" ],
        "using_compressed_ordinary_object_pointers" : "true"
      },
      "thread_pool" : { … }
      "transport" : {
        "bound_address" : [ "127.0.0.1:9300" ],
        "publish_address" : "127.0.0.1:9300",
        "profiles" : { }
      },
      "http" : {
        "bound_address" : [ "127.0.0.1:9200" ],
        "publish_address" : "127.0.0.1:9200",
        "max_content_length_in_bytes" : 104857600
      },
      "plugins" : [ ],
      "modules" : [ ]
    }
  }
}

@warkolm kindly pointed me at the cat nodes API which contains the required information:

$ curl -s 'http://127.0.0.1:9200/_cat/nodes?h=n,r'
custom-client-node c
King Bedlam        d
1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.