New Elasticsearch client - Search response cannot be serialized because of null value on sort fields

I am migrating elasticsearch from old to new elasticsearch java client.

I encounter this problem wherein I issue a request query, then the response has null values.
The code below is how I request:

    SearchRequest request = requestBuilder.build();
    SearchResponse<ObjectNode> response;
    try {
      response = elasticCLient.search(request, ObjectNode.class);
    } catch (final IOException e) {
      throw Exception(e);
    }

As you can see it uses ObjectNode.class
Problem arises when the response has null value.
A null pointer exception happens which I think the response cannot be serialized because of the null value.

The response when viewed in kibana is like this:

{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [
      {
        "_index" : "robots_20220613111538",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : null,
        "_source" : {
          "path" : "C:/storage/1",
          "name" : "barbie.jpg",
          "collection" : [ ]
        },
        "sort" : [
          null,
          "barbie.jp",
          1664377265000
        ]
      },
      {
        "_index" : "robots_20220613111538",
        "_type" : "_doc",
        "_id" : "3",
        "_score" : null,
        "_source" : {
          "path" : C:/storage/1",
          "name" : "hellokitty.jpg",
          "collection" : [ ]
        },
        "sort" : [
          null,
          "hellokitty.jpg",
          1664377266000
        ]
      }
    ]
  }
}

How to deal with this kind of response?

Are there other ways instead of using ObjectNode.class ?

Any help is greatly appreciated.

I think this causes the exception because of the null value

This is a sort field response from a query

Is it possible to ignore this null values of sort?

could this be an a bug of the new elasticsearch java client API?

the old Rest High Level elasticsearch client can handle this kind of response....

Im using co.elastic.clients 7.17.4

@swallez

this is in the debug watch

this is the query used:

POST/robots/_search?typed_keys=true&ignore_unavailable=true{
  "_source": {
    "includes": [
      "id",
      "name",
      "path"
    ]
  },
  "from": 0,
  "query": {
    "bool": {
      "minimum_should_match": "1",
      "should": [
        {
          "bool": {
            "must": [
              {
                "term": {
                  "path.full": {
                    "value": "C:/robot_data"
                  }
                }
              }
            ]
          }
        }
      ]
    }
  },
  "size": 1000,
  "sort": [
    {
      "cmeta_str-0001.lowercase": {
        "missing": "_first",
        "order": "asc",
        "unmapped_type": "keyword"
      }
    },
    {
      "name.lowercase": {
        "order": "asc"
      }
    },
    {
      "importedAt": {
        "order": "desc"
      }
    }
  ],
  "track_total_hits": true
}

Hi @ALX_DM

I suspect here. This list is with elements nulls and the serialization broken.

I recommend open a issue in Git.

@RabBit_BR

Thank you for your reply.

I search in git and found this issue null value in SearchResponse.hits.hits.sort causes parsing failure · Issue #66 · elastic/elasticsearch-java · GitHub

It seems to be resolved in 7.16.2 according to this thread Failure with sorts and new co.elastic.clients:elasticsearch-java client - #11 by swallez

But I am using 7.17.4...it is still happening.

Hope @swallez can comment on this?

i open an issue in git null value in sort hit response causes parsing failure - throws nullpointerexception · Issue #412 · elastic/elasticsearch-java · GitHub

This was the fix in 7.16.2

But it still throws NullPointerException when hits.toString() is called

Currently I am using 7.17.6

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