How to get the distinct node property

Hi,
I am trying following query to get the node distinct property

query = """{
            all (func: has(_People)){
                expand(_all_)
            }
        }"""

and i am getting result is as follow and it also coming in key value paired

{'all': [{'_People': '*', 'title': 'Delta', 'age': 40}, {'_People': '*', 'title': 'Alpha', 'age': 10}, {'_People': '*', 'title': 'Beta', 'age': 20}, {'_People': '*', 'title': 'Charlie', 'age': 30}, {'_People': '*', 'title': 'Delta', 'age': 150}, {'city': 'Mumbai', '_People': '*', 'title': 'Echo', 'age': 40}]}

and i want result, contains only the property, not values and relationship

"{'all':['_People', 'age', 'title", 'city']"
1 Like

If you are using the “Has” function. It will return absolutely all existing Nodes with the same predicate indicated. You could only differ if each node had a unique predicate or if you add an indexing and so use @filter.

It would be
has(_People)) @filter (eq (age, 30))

About has: https://docs.dgraph.io/query-language#has
About filters: https://docs.dgraph.io/query-language#connecting-filters

Whether you want specific predicates in the response. Do not use “expand (all)” the proposal of expand (all) is just “expand all”. Put in the query field only the predicates you want to return.

About expands: https://docs.dgraph.io/query-language#expand-predicates

If you want to know the existing predicates regarding the query. Use as the query below:

{
            all (func: has(_People)){
                _predicate_
            }
        }