Skip to content

Add a check on GeoCentroidAgg for the NEST client 5.x when analyzing StatsAgg  #3342

@sergey-borisenko

Description

@sergey-borisenko

NEST/Elasticsearch.Net version: < 6.x

Elasticsearch version: >= 5.5.0

Description of the problem including expected versus actual behavior:
The NullReferenceException occurre when the GeoCentroid aggregation does not have any documents.

Steps to reproduce:

  1. You should have:
    a) Elasticsearch with version greater or equal 5.5.0
    b) NEST client (for example 5.6.3)

  2. Create Index with this mapping

{
  "coordinate": {
    "type": "geo_point"
  },
  "color": {
    "type": "keyword"
  }
}
  1. Then send request (any request wich return empty search context). We have empty index, so in our case, any request.
{
  "size": 0,
  "query": {
    "term": {
      "color": "black"
    }
  },
  "aggs": {
    "geo_centroid_agg": {
      "geo_centroid": {
        "field": "coordinate"
      }
    }
  }
}

Result for version >= 5.5.0:

{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 3,
    "successful": 3,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "geo_centroid_agg": {
      "count": 0
    }
  }
}

Result for version < 5.5.0:

{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 3,
    "successful": 3,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "geo_centroid_agg": {}
  }
}
  1. You got the NullReferenceException
at Nest.AggregateJsonConverter.GetStatsAggregate(Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.JsonSerializer serializer) at offset 252
at Nest.AggregateJsonConverter.ReadAggregate(Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.JsonSerializer serializer) at offset 504
at Nest.AggregateJsonConverter.GetSubAggregates(Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.JsonSerializer serializer) at offset 43
at Nest.AggregateJsonConverter.GetSingleBucketAggregate(Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.JsonSerializer serializer) at offset 264
at Nest.AggregateJsonConverter.ReadAggregate(Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.JsonSerializer serializer) at offset 515
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(Newtonsoft.Json.JsonConverter converter, Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Object existingValue) at offset 74

Without property "location" the property "count" interpreted as the begin of StatsAggregate.
I think that the history of this problem began in this task elastic/elasticsearch#24387

Please, add this fix https://github.com/elastic/elasticsearch-net/blame/52566943f3e0bf70f747ff8e35f70c303c56e1e3/src/Nest/Aggregations/AggregateJsonConverter.cs#L338
for next minor version 5.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions