How to return only keys from map based on have top 2 Values

I have a map like where keys are names, values are some count like e.g. {umakanth:10,sai:20,ravi:5,raju:25}

image

I need only 2 keys in that map where corresponding Values are highest.
In this example I need to get 2 keys that is sai,raju.

Thanks in Advance .

Interesting question, there is no easy way to sort a map by value. APOC only supports it by key.
See http://neo4j-contrib.github.io/neo4j-apoc-procedures/3.5/utilities/map-functions/ for more info.

What is your use-case? With a bit more context a different way of getting there might present itself.

You could do something like:

WITH {umakanth:10,sai:20,ravi:5,raju:25} as props
UNWIND keys(props) as key
WITH key, props[key] as value
ORDER BY value DESC
RETURN key, value
LIMIT 2
1 Like