Searching for a value in consule kv

Is there a way to do a reverse lookup on a consul kv map? If I know the value, and want to find the associated key.

Not done yet, but you could combine recurse (https://www.consul.io/api/kv.html#recurse) and the json output with the possibility to search using jq (https://stackoverflow.com/a/18608100).

1 Like

I see. Thank you.
So with recurse: true, I get all the keys, with their values. And then from the json response, I would lookup the value I want to search and find the associated key. Right?

That would be my theory.

and is there a way I can use consul https api to get all the kv values with a single curl command?

As @jsosulska mentioned in another thread:
curl -k 'localhost:8500/v1/kv/?recurse'

1 Like

Hi @kkimaya,

Welcome to the forums! As @Wolfsrudel posted, recurse would be your best option. @iamdempa had a great thread on this, here.

Hope this helps!

Yep! that did help. we were just trying to do a POC and see what’s most feasible. Thinking about the bigger picture, it was kinda to hide a design flaw at my end. So good thing there’s not an easy way out :slight_smile:

1 Like