Skip to content

Introduce IPRangeBucket type for IpRange aggregation #3550

@russcam

Description

@russcam

The current RangeBucket implementation ignores "from" and "to" for an ip_range aggregation, by looking at the JSON token type when deserializing, and only deserializing when it is a number:

case Parser.From:
reader.Read();
if (reader.ValueType == typeof(double))
fromDouble = (double)reader.Value;
reader.Read();
break;
case Parser.To:
reader.Read();
if (reader.ValueType == typeof(double))
toDouble = (double)reader.Value;
reader.Read();
break;

This ignores "from" and "to" string values for ip_range aggregation, an example response being

{
  "took" : 39,
  "timed_out" : false,
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 1100,
    "max_score" : 0.0,
    "hits" : [ ]
  },
  "aggregations" : {
    "ip_range#ip_ranges" : {
      "buckets" : [
        {
          "key" : "*-127.0.0.1",
          "to" : "127.0.0.1",
          "doc_count" : 52
        },
        {
          "key" : "127.0.0.1-*",
          "from" : "127.0.0.1",
          "doc_count" : 48
        }
      ]
    }
  }
}

Introduce an IpRangeBucket type or make RangeBucket a generic type, i.e.

public class RangeBucket<TRangeValue> : BucketBase, IBucket
{
	public RangeBucket(IReadOnlyDictionary<string, IAggregate> dict) : base(dict) { }

	public long DocCount { get; set; }
	public TRangeValue From { get; set; }
	public string FromAsString { get; set; }

	public string Key { get; set; }
	public TRangeValue To { get; set; }
	public string ToAsString { get; set; }
}

An IpRangeBucket type is probably better here, since FromAsString and ToAsString are not properties of the response.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions