# How to get result of a type limited by x correctly?

**URL:** <https://discuss.dgraph.io/t/how-to-get-result-of-a-type-limited-by-x-correctly/5635>\
**Category:** Dgraph\
**Created:** [December 14, 2019, 12:26am UTC](https://discuss.dgraph.io/t/how-to-get-result-of-a-type-limited-by-x-correctly/5635 "2019-12-14T00:26:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnsiu2016](https://avatars.discourse-cdn.com/v4/letter/j/ba9def/32.png) [@johnsiu2016](https://discuss.dgraph.io/u/johnsiu2016)\
**Post date:** [December 14, 2019, 12:26am UTC](https://discuss.dgraph.io/t/how-to-get-result-of-a-type-limited-by-x-correctly/5635/1 "2019-12-14T00:26:02Z")

</div>

I am studying the type system and as I saw the doc said

 ![image](https://canada1.discourse-cdn.com/flex007/uploads/dgraph/original/2X/c/cf065fd7ee2bc7efbf043a212ffc034b78a3a507.png)

I sent a query

```auto
{
  q(func: type(Person), first:5) {
 	 name@en
	}
}

```

and I got the result

```auto
{
  "data": {
    "q": [
      {
        "name@en": "Steve Santa Sekiyoshi"
      }
    ]
  },
  "extensions": {
    "server_latency": {
      "parsing_ns": 23600,
      "processing_ns": 30901100,
      "encoding_ns": 15100,
      "assign_timestamp_ns": 1101000
    },
    "txn": {
      "start_ts": 60309
    }
  }
}

```

but when i use this

```auto
{
  q(func: has(name@en), first:5) @filter(type(Person)) {
 	 name@en
	}
}

```

The result is

```auto
{
  "data": {
    "q": [
      {
        "name@en": "Steve Santa Sekiyoshi"
      },
      {
        "name@en": "Kirstie Bingham"
      },
      {
        "name@en": "Domenica Cameron-Scorsese"
      },
      {
        "name@en": "William Garcia"
      },
      {
        "name@en": "Coleman Horn"
      }
    ]
  },
  "extensions": {
    "server_latency": {
      "parsing_ns": 25400,
      "processing_ns": 1506232300,
      "encoding_ns": 27800,
      "assign_timestamp_ns": 1056200
    },
    "txn": {
      "start_ts": 60999
    }
  }
}

```

This really confused me. The “first: 5” in first query seems skipping some node that is not the type of “Person”. So it skipped first 4 node that is not type “Person” and return the 5th one that is a type “Person”.

---

<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:** [December 14, 2019, 1:14am UTC](https://discuss.dgraph.io/t/how-to-get-result-of-a-type-limited-by-x-correctly/5635/2 "2019-12-14T01:14:31Z")

</div>

All of your entities of Persons has the `"dgraph.type": "Person"`  
OR in RDF `<0x1> <dgraph.type> "Person" . ` in the dataset?

---

<div class="post-metadata">

**Author:** ![johnsiu2016](https://avatars.discourse-cdn.com/v4/letter/j/ba9def/32.png) [@johnsiu2016](https://discuss.dgraph.io/u/johnsiu2016)\
**Post date:** [December 14, 2019, 2:08am UTC](https://discuss.dgraph.io/t/how-to-get-result-of-a-type-limited-by-x-correctly/5635/3 "2019-12-14T02:08:41Z")

</div>

```auto
{
  q(func: has(name@en), first:5) @filter(type(Person)) {
 	 	name@en
    dgraph.type
	}
}

```

```auto
{
  "data": {
    "q": [
      {
        "name@en": "Steve Santa Sekiyoshi",
        "dgraph.type": [
          "Person"
        ]
      },
      {
        "name@en": "Kirstie Bingham",
        "dgraph.type": [
          "Person"
        ]
      },
      {
        "name@en": "Domenica Cameron-Scorsese",
        "dgraph.type": [
          "Person"
        ]
      },
      {
        "name@en": "William Garcia",
        "dgraph.type": [
          "Person"
        ]
      },
      {
        "name@en": "Coleman Horn",
        "dgraph.type": [
          "Person"
        ]
      }
    ]
  },
  "extensions": {
    "server_latency": {
      "parsing_ns": 31500,
      "processing_ns": 1392594800,
      "encoding_ns": 25200,
      "assign_timestamp_ns": 1085900
    },
    "txn": {
      "start_ts": 79430
    }
  }
}

```

 ![image](https://canada1.discourse-cdn.com/flex007/uploads/dgraph/original/2X/8/887059989b7632b4465f61d979dda48c6a59c2b8.png)

---

<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:** [December 14, 2019, 2:12am UTC](https://discuss.dgraph.io/t/how-to-get-result-of-a-type-limited-by-x-correctly/5635/4 "2019-12-14T02:12:30Z")

</div>

Yeah, this is odd. @martinmr potential bug with Type + pagination.

---

<div class="post-metadata">

**Author:** ![martinmr](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/martinmr/32/1408_2.png) [@martinmr](https://discuss.dgraph.io/u/martinmr)\
**Post date:** [December 16, 2019, 7:40pm UTC](https://discuss.dgraph.io/t/how-to-get-result-of-a-type-limited-by-x-correctly/5635/5 "2019-12-16T19:40:05Z")

</div>

Looks like an issue indeed. I’ll look into it.

---

<div class="post-metadata">

**Author:** ![martinmr](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/martinmr/32/1408_2.png) [@martinmr](https://discuss.dgraph.io/u/martinmr)\
**Post date:** [December 16, 2019, 8:22pm UTC](https://discuss.dgraph.io/t/how-to-get-result-of-a-type-limited-by-x-correctly/5635/6 "2019-12-16T20:22:10Z")

</div>

Actually, I just went through the queries again and I don’t think there’s an issue. Let me explain further.

```auto
{
  q(func: type(Person), first:5) {
 	 name@en
	}
}

```

This query is getting the first five nodes with a `dgraph.type` value. These nodes are not guaranteed to have a name (or more specifically a name with a `@en` tag). If they don’t they won’t show up in the results. You can make them show up by changing the query to.

```auto
{
  q(func: type(Person), first:5) {
    uid
    name@en
  }
}

```

The other query goes through all the nodes that have a `name@en` value. Since we tagged all the nodes with a type in this dataset, the five results show up.

Hope this helps clear up why the results of the two queries are different.
