# Recurse query limiting the number of results - not based on depth

**URL:** <https://discuss.dgraph.io/t/recurse-query-limiting-the-number-of-results-not-based-on-depth/4609>\
**Category:** Users\
**Created:** [June 12, 2019, 3:41pm UTC](https://discuss.dgraph.io/t/recurse-query-limiting-the-number-of-results-not-based-on-depth/4609 "2019-06-12T15:41:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CondeChocula](https://avatars.discourse-cdn.com/v4/letter/c/a8b319/32.png) [@CondeChocula](https://discuss.dgraph.io/u/CondeChocula)\
**Post date:** [June 12, 2019, 3:41pm UTC](https://discuss.dgraph.io/t/recurse-query-limiting-the-number-of-results-not-based-on-depth/4609/1 "2019-06-12T15:41:39Z")

</div>

I’m trying to make a query similar to this and having trouble finding any examples that combine @recurse with filtering on the relationships,

```auto
{ log (func: uid(x)) @recurse  
    name 
    parent      
}

```

Here parent has it self a name and that can recurse quite deep.

I get back a nested structure like

```auto
log{
  name: name1
  parent {
     name: name2
     parent {
       name: name3
    }
  }

```

I’d like to filter (ie, don’t want them returned) any part node on the tree that matches a name for example, but i only manage cut the tree on the first one that doesn’t match not getting any of the deeper nodes and doesn’t lose information about the shape of the graph, still want to keep know whose node is a parent of another.

It might be a data modelling problem in the first place but I wonder if that query is possible

Thanks.

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [June 13, 2019, 2:15pm UTC](https://discuss.dgraph.io/t/recurse-query-limiting-the-number-of-results-not-based-on-depth/4609/2 "2019-06-13T14:15:36Z")

</div>

> Recurse query limiting the number of results

You can’t. Just depth.  
BTW, you could try to use “first” on edges. But It would cost performance.

> [@CondeChocula](#):
>
> @recurse with filtering on the relationships,

You can add a filter to an Edge. eg:

```auto
{ log (func: uid(x)) @recurse  
    name 
    parent @filter(Not eq(name, "something")) (first: 300)
}

```

This will be applied recursively.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex007/uploads/dgraph/original/2X/2/2b38fdece2abe5814f2e51bee69d1e67fc304b0a.png) [@system](https://discuss.dgraph.io/u/system)\
**Post date:** [July 13, 2019, 2:15pm UTC](https://discuss.dgraph.io/t/recurse-query-limiting-the-number-of-results-not-based-on-depth/4609/3 "2019-07-13T14:15:37Z")

</div>

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