_cat/nodeattrs - empty echo

Hello,
ES: elasticsearch-5.5.2-1.noarch

I need to assign node id to bash variable and I expected to get it this way:

# curl -s -XGET 'http://ip:9200/_cat/nodeattrs'
# curl -s -XGET 'http://ip:9200/_cat/nodeattrs?v&h=name,pid,attr,value'
name pid attr value
#

Why does it return empty echo?
I can get it this way:

# curl -s -XGET 'http://ip:9200/_cat/nodes?v&full_id=true&h=id'
id
BWNZ3xyOSYKo7CVDRGogvA
7pXQ9qfFRpWkc8GBmtHwdg
F_qcivzzSzG_GCaemMOnUA
tZi7lnw7R2S3NBq56G-ZBw
Et90JFMjRaCvjxkaX8Cnmg
69EhNIkFQoSreSbxgIC4oQ

but I need just one, current host node id.

Hi @erde,

you can probably parse it out of the response for:

curl 'localhost:9200/_nodes/_local'

though you will need to parse the JSON output.

Thank you for your answer.
I know but I couldn't do it so I looked for another way and hoped '_cat/nodeattrs' do it for me.
It is not so easy to get id because it is not in 'variable: value;' format so I can not use:

curl -s -XGET 'http://localhost:9200/_nodes/_local' | python -c "import sys, json; print json.load(sys.stdin)['nodes'][SOMETHING SHOULD BE HERE]"

I haven't got an idea how to manage it.

I have managed to get node id:

curl -s -XGET "http://localhost:9200/_nodes/$(hostname -s)/stats/" | python -c "import sys, json; print json.load(sys.stdin)['nodes'].keys()"| cut -d"'" -f2

and the complete result of my work, host independent one-liner to get metrics:

export nodeID=`curl -s -XGET "http://localhost:9200/_nodes/$(hostname -s)/stats/" | python -c "import sys, json; print json.load(sys.stdin)['nodes'].keys()"| cut -d"'" -f2`;curl -s -XGET "http://localhost:9200/_nodes/$(hostname -s)/stats/os" | python -c "import os, sys, json; print json.load(sys.stdin)['nodes'][os.environ['nodeID']]['os']['mem']['total_in_bytes']"

simple! :slight_smile:

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