1. filter's query is a plain string 2. filter's query is a query_string query 3. filter's query is some other query DSL object
This commit is contained in:
parent
cae5a0da45
commit
cc3092af29
|
@ -242,7 +242,16 @@ describe('buildHierarchicalData', function () {
|
|||
schema: 'group',
|
||||
params: {
|
||||
field: 'geo.src',
|
||||
filters: [ { label: 'type:apache' }, { label: 'type:nginx' } ]
|
||||
filters: [
|
||||
{
|
||||
label: 'type:apache',
|
||||
input: { query: 'type:apache' },
|
||||
},
|
||||
{
|
||||
label: 'type:nginx',
|
||||
input: { query: 'type:nginx' },
|
||||
},
|
||||
],
|
||||
}
|
||||
}];
|
||||
results = await buildHierarchicalData(aggs, fixtures.oneFilterBucket);
|
||||
|
|
|
@ -53,6 +53,87 @@ describe('Buckets wrapper', function () {
|
|||
const keys = ['0-100', '100-200', '200-300'];
|
||||
|
||||
test(aggResp, count, keys);
|
||||
|
||||
it('should accept filters agg queries with strings', () => {
|
||||
const aggResp = {
|
||||
buckets: {
|
||||
'response:200': {},
|
||||
'response:404': {},
|
||||
}
|
||||
};
|
||||
|
||||
const aggParams = {
|
||||
filters: [
|
||||
{
|
||||
label: '',
|
||||
input: { query: 'response:200' },
|
||||
},
|
||||
{
|
||||
label: '',
|
||||
input: { query: 'response:404' },
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const buckets = new TabifyBuckets(aggResp, aggParams);
|
||||
expect(buckets).to.have.length(2);
|
||||
buckets._keys.forEach((key) => {
|
||||
expect(key).to.be.a('string');
|
||||
});
|
||||
});
|
||||
|
||||
it('should accept filters agg queries with query_string queries', () => {
|
||||
const aggResp = {
|
||||
buckets: {
|
||||
'response:200': {},
|
||||
'response:404': {},
|
||||
}
|
||||
};
|
||||
|
||||
const aggParams = {
|
||||
filters: [
|
||||
{
|
||||
label: '',
|
||||
input: { query: { query_string: { query: 'response:200' } } },
|
||||
},
|
||||
{
|
||||
label: '',
|
||||
input: { query: { query_string: { query: 'response:404' } } },
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const buckets = new TabifyBuckets(aggResp, aggParams);
|
||||
expect(buckets).to.have.length(2);
|
||||
buckets._keys.forEach((key) => {
|
||||
expect(key).to.be.a('string');
|
||||
});
|
||||
});
|
||||
|
||||
it('should accept filters agg queries with query dsl queries', () => {
|
||||
const aggResp = {
|
||||
buckets: {
|
||||
'{match_all: {}}': {},
|
||||
}
|
||||
};
|
||||
|
||||
const aggParams = {
|
||||
filters: [
|
||||
{
|
||||
label: '',
|
||||
input: { query: { match_all: {} } },
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const buckets = new TabifyBuckets(aggResp, aggParams);
|
||||
expect(buckets).to.have.length(1);
|
||||
buckets._keys.forEach((key) => {
|
||||
expect(key).to.be.a('string');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
describe('with array style buckets', function () {
|
||||
|
|
|
@ -68,7 +68,9 @@ TabifyBuckets.prototype._isRangeEqual = function (range1, range2) {
|
|||
TabifyBuckets.prototype._orderBucketsAccordingToParams = function (params) {
|
||||
if (params.filters && this.objectMode) {
|
||||
this._keys = params.filters.map(filter => {
|
||||
return filter.label || filter.input.query || '*';
|
||||
const query = _.get(filter, 'input.query.query_string.query', filter.input.query);
|
||||
const queryString = typeof query === 'string' ? query : JSON.stringify(query);
|
||||
return filter.label || queryString || '*';
|
||||
});
|
||||
} else if (params.ranges && this.objectMode) {
|
||||
this._keys = params.ranges.map(range => {
|
||||
|
|
Loading…
Reference in a new issue