---------

**Commit 1:**
Generate key for ip range from/to agg

Elasticsearch 5.0 no longer returns a `key` prop with ip range buckets
when from/to is used in the request. Looking at the [2.x docs][1] it
appears to be a mistake that it was ever included in the first place.
So now we'll generate the key ourselves.

[1]: https://www.elastic.co/guide/en/elasticsearch/reference/2.4/search-aggregations-bucket-iprange-aggregation.html

Fixes: https://github.com/elastic/kibana/issues/8736

* Original sha: f344a4b262
* Authored by Matthew Bargar <mbargar@gmail.com> on 2016-10-18T22:51:56Z

**Commit 2:**
Stop sending null in ip range from/to props

The IP range agg supports open ended ranges. Elasticsearch 2.x was
lenient and accepted null as a value for the from/to props, but the
correct way to do an open ended range was always to omit the from/to
key entirely. ES 5.0 appears to be more strict and barfs when null is
passed. This commit removes the null values.

Fixes https://github.com/elastic/kibana/issues/8741

* Original sha: 3ca45ba546
* Authored by Matthew Bargar <mbargar@gmail.com> on 2016-10-18T23:18:14Z

**Commit 3:**
ip range label and filter improvements

* updated the filter labels to match the range labels
* fixed the filter creation to work for unbound ranges

* Original sha: b153ea0da3
* Authored by Spencer <spalger@users.noreply.github.com> on 2016-10-19T17:57:58Z
* Committed by Matthew Bargar <mbargar@gmail.com> on 2016-10-19T18:36:22Z
This commit is contained in:
spalger 2016-10-19 12:14:58 -07:00
parent 381cd82a35
commit 5f33808d1a
3 changed files with 20 additions and 6 deletions

View file

@ -41,7 +41,7 @@ describe('AggConfig Filters', function () {
});
let aggConfig = vis.aggs.byTypeName.ip_range[0];
let filter = createFilter(aggConfig, '0.0.0.0-1.1.1.1');
let filter = createFilter(aggConfig, '0.0.0.0 to 1.1.1.1');
expect(filter).to.have.property('range');
expect(filter).to.have.property('meta');
expect(filter.meta).to.have.property('index', indexPattern.id);

View file

@ -6,10 +6,10 @@ export default function createIpRangeFilterProvider() {
if (aggConfig.params.ipRangeType === 'mask') {
range = new CidrMask(key).getRange();
} else {
let addresses = key.split(/\-/);
let [from, to] = key.split(/\s+to\s+/);
range = {
from: addresses[0],
to: addresses[1]
from: from === '-Infinity' ? -Infinity : from,
to: to === 'Infinity' ? Infinity : to
};
}

View file

@ -13,6 +13,12 @@ export default function RangeAggDefinition(Private) {
name: 'ip_range',
title: 'IPv4 Range',
createFilter: createFilter,
getKey: function (bucket, key, agg) {
if (key) return key;
const from = _.get(bucket, 'from', '-Infinity');
const to = _.get(bucket, 'to', 'Infinity');
return `${from} to ${to}`;
},
makeLabel: function (aggConfig) {
return aggConfig.params.field.displayName + ' IP ranges';
},
@ -38,8 +44,16 @@ export default function RangeAggDefinition(Private) {
},
editor: ipRangesTemplate,
write: function (aggConfig, output) {
let ipRangeType = aggConfig.params.ipRangeType;
output.params.ranges = aggConfig.params.ranges[ipRangeType];
const ipRangeType = aggConfig.params.ipRangeType;
let ranges = aggConfig.params.ranges[ipRangeType];
if (ipRangeType === 'fromTo') {
ranges = _.map(ranges, (range) => {
return _.omit(range, _.isNull);
});
}
output.params.ranges = ranges;
}
}
]