Search after and nil values

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

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