How to make the query results not duplicate

code like

{
  var(func: eq(id, 933)) @filter(type(Person)){
    A1 as knows{
      uid
      A2 as knows{
        uid
        A3 as knows{
          uid
        }
      }
    }
  }
}

I want A1, A2, A3 to have no duplicate nodes for each other
(Since A1, A2, A3 will be used later, recursion is not allowed)
so, How to make the query results not duplicate?

Not sure if I get it, does this works for you?

{
  var(func: eq(id, 933)) @filter(type(Person)) @recurse(depth: 3, loop: false) {
    uid
    A as knows
  }
}

@MichelDiz
I want to get the nodes that a person is associated with in three degrees and return the distance from each node to this person.

what do you mean by distance? geo?

The recurse query will traverse three levels and all the uids will be in A variable.

This will be accomplished with the recurse query. As all nodes will be in the variable A. Variables can hold only unique uids.

@MichelDiz
no no no
data:
A - knows - B - knows - C - knows - D

I want to return:
B:{distance: 1}
C:{distance: 2}
D:{distance: 3}

But where this distance would come from? Dgraph doesn’t have anything like it. Unless you use math(var), but that is manual input.

@MichelDiz
Yes, I used math

{ 
    Q(func: uid(933)){
         knows{
            Distance: math(1)  # B
             knows{
                   Distance: math(2)  # C
                   knows{
                        Distance: math(3)  # D
                    }
              }
          }

But in this way, some people both in B and C, is error result. If People in B, then he can not in C.
What should I do?

Returning to this pattern. I don’t think it is like this. I think it should look like

{ var A - edge -> Any* {
  var B - edge -> Any* { var C - edge -> Any* }}}

Cuz the variable will collect all nodes on that edge and it can be one or more nodes there. Your pattern feels like it is stating that it would return always 1:1 relations.

The math part isn’t exactly what I was mentioning. You could potentially use a kind of aggregation via levels. And maybe use k-shortest-path.

Maybe I’m tired, I had a long day. But I’m not able to get what you wanna do. The main question felt to be like, “How to remove duplicate nodes from a result”. After you mentioned about counting degrees. And this last question I get totally without a north.

I’m got wrong the first issue? if not so, can you state that I was (at least one of your issues) solved?

If we sync, we might go to the k-shortest path. But I need to understand what you need for real. Show me in “before, after” with JSON results. What you would like to see as a result.

@MichelDiz

Actually,I have more question:

       Q(func: uid(933)){
              knows{
               firstName
               hasCea @filter(lt(creationDate, “2020-01-01”)){
               I’d
               }
         }
     }

some people hasCea ‘s creationDate>2020-01-01 but also be return, I just want people who creationDate < 2020-01-01

What should I do??

Sorry my bad. It was an Edge. Let me check again the question.

Feels like a cascade should do the trick

Q(func: uid(933)) @cascade {
              knows{
               firstName
               hasCea @filter(lt(creationDate, “2020-01-01”)){
               I’d
               }
         }
     }

Cascade will show only nodes that matches all in the query counting the root to the last nested field.

@MichelDiz
think you !

@MichelDiz
reply 3d:
my code like this:

{	
  var(func: eq(id, 933)) @filter(type(Person)){
    A1 as knows{
      uid
      A2 as knows{
        uid
        A3 as knows{
          uid
        }
      }
    }
  }
  knows_info(func: uid(A1)) @filter(type(Person)){
   	  uid
      id
    	distanceFromPerson: math(1)
  }
    knows_info2(func: uid(A2))@filter((not uid_in(A1)) and type(Person)){
   	  uid 
      id
    	distanceFromPerson: math(2)
  }
      knows_info3(func: uid(A3))@filter((not uid_in(A1)) and (not uid_in(A2)) and type(Person)){
   	  uid 
      id
    	distanceFromPerson: math(3)
  }
  
}

This code is stupid. Do you have any suggestions??

Sorry, I have no idea hwo to help you there. There’s no method to check and give the leve/degree/position of the nested levels in Dgraph. All we can do is doing manual inputs with math func. But that is somewhat useless.

Maybe we need a ticket for that feature. To give us the level, that can be useful in Recurse queries. Also, we have the k-shortest path https://dgraph.io/docs/query-language/kshortest-path-quries/#sidebar - It is very useful to see the path between two known objects. But I think it also needs some useful methods like “Give us the count of hops of each path found”. And other things.

I think that thing you wanna do only can be accomplished via your side application. Dgraph can’t do this.

Cheers.