# Search after and nil values

**URL:** <https://discuss.elastic.co/t/search-after-and-nil-values/232246>\
**Category:** Elasticsearch\
**Created:** [May 12, 2020, 2:40pm UTC](https://discuss.elastic.co/t/search-after-and-nil-values/232246 "2020-05-12T14:40:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![apassant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/apassant/32/68163_2.png) [@apassant](https://discuss.elastic.co/u/apassant)\
**Post date:** [May 12, 2020, 2:40pm UTC](https://discuss.elastic.co/t/search-after-and-nil-values/232246/1 "2020-05-12T14:40:12Z")

</div>

Hi everyone!

We're using `search_after` to retrieve items from ES and have an issue with `nil` values. Specifically, we search for items sorted by date (`last_seen_at`), using `internal_id` (indexed copy of `_id`) as a tie-breaker.

Most records have a value for `last_seen_at`, but some don't. But passing `nil` for `search_after` (as below) raises a `NullPointerException`. It works fine using `0`, but I guess it searches for items having an existing value of `0`, instead of items with no value?

```
{
  "query": {
    "bool": {
      "filter": {
        "bool": {
          "must": [{
            "term": { "team_id": 44 }
          }, {
            "exists": { "field": "user_id"}
          }]
        }
      }
    }
  },
  "sort": [{
    "last_request_at": { "order": "desc"}
  }, {
    "internal_id": { "order": "asc"}
  }],
  "size": "10",
  "search_after": [nil, "5e79de5f33640a29a0027d41"]
}

```

Is there a way to retrieve items having a `nil` value w/ `search_after`? Something like `missing` values for this?

Many thanks!

NB: Using ES 6.8

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 9, 2020, 2:40pm UTC](https://discuss.elastic.co/t/search-after-and-nil-values/232246/2 "2020-06-09T14:40:14Z")

</div>

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