# UID query not working with @filter

**URL:** <https://discuss.dgraph.io/t/uid-query-not-working-with-filter/7750>\
**Category:** Dgraph Clients\
**Tags:** untagged, dgraph4j\
**Created:** [June 19, 2018, 4:59am UTC](https://discuss.dgraph.io/t/uid-query-not-working-with-filter/7750 "2018-06-19T04:59:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [June 19, 2018, 4:59am UTC](https://discuss.dgraph.io/t/uid-query-not-working-with-filter/7750/1 "2018-06-19T04:59:40Z")

</div>

_Posted by_ [piyushGoyal2](https://github.com/piyushGoyal2):

Hi Team,

I ran a query from Ratel where I am doing a **uid** query using **@filter**. From Ratel I can see the response is perfectly fine. Then I exported the same query into java application. Here the response seems partial in the sense that whatever data is expected after the filter is missing.  
Here is the query:

`String query = "query all($idVal: string, $userID: string){ getCircleByUIDAndCID(func: eq(idVal, $idVal)){ uid idVal ~accounts @filter(uid($userID)) { uid firstName belongsTo { uid name } }}}";`

With parameters:

```
      parameterMap.put("$idVal","001w000001NFA6dAAC");
      parameterMap.put("$userID","0x9fc9");

```

As a next step, I thought to replace the **uid** query with **eq** on the **firstName** field from java client and this absolutely works fine.

Here is the query with the **eq**  
`query = "query all($idVal: string, $userName: string){ getCircleByUIDAndCID(func: eq(idVal, $idVal)){ uid idVal ~accounts @filter(eq(firstName, $userName)) { uid firstName belongsTo { uid name } }}}";`  
With parameters:

```
    parameterMap.put("$idVal","001w000001NFA6dAAC");
    parameterMap.put("$userName", "userName");

```

Any reasons for why **uid** query doesn’t work with @filter?

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [July 2, 2018, 4:10am UTC](https://discuss.dgraph.io/t/uid-query-not-working-with-filter/7750/2 "2018-07-02T04:10:13Z")

</div>

[piyushGoyal2](https://github.com/piyushGoyal2) _commented_ :

As a next step as recommended by @manishrjain we looked at the DGraph logs in debug mode for a uid query with a filter and please find the screenshots attached.

 ![dgraph_query_screenshot2018-06-21 12-18-44](https://canada1.discourse-cdn.com/flex007/uploads/dgraph/original/2X/8/8f696fd581c36cdba69cd2c58e480a79ced1d8db.png)

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [March 18, 2019, 6:47pm UTC](https://discuss.dgraph.io/t/uid-query-not-working-with-filter/7750/3 "2019-03-18T18:47:21Z")

</div>

[MichelDiz](https://github.com/MichelDiz) _commented_ :

This is indeed strange with uid func. But another tip would be try with uid\_in I suspect it would work with Java. And It has the same effect.

```auto
query all($idVal: string, $userID: string){ 
getCircleByUIDAndCID(func: eq(idVal, $idVal)) @filter(uid_in(~accounts, $userID))
{ 
  uid 
  idVal 
  ~accounts { 
    uid 
    firstName 
    belongsTo { 
      uid 
      name 
    } 
  }
  }
}

```

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [July 12, 2019, 10:21pm UTC](https://discuss.dgraph.io/t/uid-query-not-working-with-filter/7750/4 "2019-07-12T22:21:04Z")

</div>

[campoy](https://github.com/campoy) _commented_ :

Hey @gitlw, any chance you could have a look at this issue?

If it’s not relevant anymore, please close it.  
Thanks!

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [July 29, 2019, 6:50pm UTC](https://discuss.dgraph.io/t/uid-query-not-working-with-filter/7750/5 "2019-07-29T18:50:37Z")

</div>

[gitlw](https://github.com/gitlw) _commented_ :

@piyushGoyal2 Thanks for reporting this issue. I tried using the following experiment and couldn’t reproduce the problem you described in the latest dgraph master.

1. Run Dgraph cluster using the latest master branch with Commit SHA-1 : cf7c1e63
2. Create the sample data set using the following commands

```auto
curl localhost:8180/alter -XPOST -d '
idVal: string @index(exact) .
account: uid @reverse .
firstName: string .
'

```

```auto
curl 'localhost:8180/mutate?commitNow=true' -H 'Content-Type:application/rdf' -XPOST -d '{
  set {
    _:one <firstName> "One" .
    _:one <account> _:two .
    _:two <idVal> "idVal" .
    
    _:three <firstName> "Three" .
    _:three <account> _:four .
    _:four <idVal> "idVal" .
  }
}'

```

1. Query the data with this sample program

```java
import io.dgraph.DgraphClient;
import io.dgraph.DgraphGrpc;
import io.dgraph.DgraphProto;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.Metadata;
import io.grpc.stub.MetadataUtils;

import java.util.HashMap;
import java.util.Map;

public class Experiment {
  private static final String TEST_HOSTNAME = "localhost";
  private static final int TEST_PORT = 9180;

  private static DgraphClient createDgraphClient(boolean withAuthHeader) {
    ManagedChannel channel =
        ManagedChannelBuilder.forAddress(TEST_HOSTNAME, TEST_PORT).usePlaintext(true).build();
    DgraphGrpc.DgraphStub stub = DgraphGrpc.newStub(channel);

    if (withAuthHeader) {
      Metadata metadata = new Metadata();
      metadata.put(
          Metadata.Key.of("auth-token", Metadata.ASCII_STRING_MARSHALLER), "the-auth-token-value");
      stub = MetadataUtils.attachHeaders(stub, metadata);
    }

    return new DgraphClient(stub);
  }

  public static void main(String[] args) {
    DgraphClient dgraphClient = createDgraphClient(false);
    final String query = " query all($idVal: string, $userID: string)" +
        "{\n" +
        " run(func: eq(idVal, $idVal)) {\n" +
        " uid\n" +
        " idVal\n" +
        " ~account @filter(uid($userID)){\n" +
        " uid\n" +
        " firstName\n" +
        " }\n" +
        " }\n"
            + "}";

    final Map<String, String> parameterMap = new HashMap<>();
    parameterMap.put("$idVal","idVal");
    parameterMap.put("$userID", "0x01");
    DgraphProto.Response response = dgraphClient.newReadOnlyTransaction().queryWithVars(query, parameterMap);

    System.out.println(response.getJson().toStringUtf8());
  }
}

```

And the result I get is

```json
{"run":[{"uid":"0x2","idVal":"idVal","~account":[{"uid":"0x1","firstName":"One"}]},{"uid":"0x4","idVal":"idVal"}]}

```

If I remove the @filter(uid(…)) part of the query, the result I get will be

```auto
{"run":[{"uid":"0x2","idVal":"idVal","~account":[{"uid":"0x1","firstName":"One"}]},{"uid":"0x4","idVal":"idVal","~account":[{"uid":"0x3","firstName":"Three"}]}]}

```

Thus the result seems correct to me.

I’m closing this issue for now, and feel free to reopen if you are still seeing this problem.

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [July 29, 2019, 8:41pm UTC](https://discuss.dgraph.io/t/uid-query-not-working-with-filter/7750/6 "2019-07-29T20:41:41Z")

</div>

[martinmr](https://github.com/martinmr) _commented_ :

@gitlw did you try to reproduce this in one of the 1.0 releases? I just realized @piyushGoyal2 didn’t specify which version of Dgraph they are using.

Sometimes issues that are fixed in master are still present in the old versions.

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [July 29, 2019, 9:09pm UTC](https://discuss.dgraph.io/t/uid-query-not-working-with-filter/7750/7 "2019-07-29T21:09:01Z")

</div>

[gitlw](https://github.com/gitlw) _commented_ :

@martinmr Thanks for the reminder. I’ve re-run the experiment against Dgraph version 1.0.16, and got the same result. @piyushGoyal2 can you please let us know which version of Dgraph you are using and whether you are still seeing this problem? Thanks!

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [July 11, 2020, 1:41am UTC](https://discuss.dgraph.io/t/uid-query-not-working-with-filter/7750/8 "2020-07-11T01:41:58Z")

</div>


