-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathnested-aggregation.js
More file actions
68 lines (59 loc) · 1.94 KB
/
nested-aggregation.js
File metadata and controls
68 lines (59 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'use strict';
const _ = require('../../_');
const BucketAggregationBase = require('./bucket-aggregation-base');
const ES_REF_URL =
'https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html';
/**
* A special single bucket aggregation that enables aggregating nested
* documents.
*
* [Elasticsearch reference](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html)
*
* @example
* const reqBody = esb.requestBodySearch()
* .query(esb.matchQuery('name', 'led tv'))
* .agg(
* esb.nestedAggregation('resellers', 'resellers').agg(
* esb.minAggregation('min_price', 'resellers.price')
* )
* );
*
* @param {string} name The name which will be used to refer to this aggregation.
* @param {string=} path `path` of the nested document
*
* @extends BucketAggregationBase
*/
class NestedAggregation extends BucketAggregationBase {
// eslint-disable-next-line require-jsdoc
constructor(name, path) {
super(name, 'nested');
if (!_.isNil(path)) this._aggsDef.path = path;
}
/**
* @override
* @throws {Error} This method cannot be called on NestedAggregation
*/
field() {
console.log(`Please refer ${ES_REF_URL}`);
throw new Error('field is not supported in NestedAggregation');
}
/**
* @override
* @throws {Error} This method cannot be called on NestedAggregation
*/
script() {
console.log(`Please refer ${ES_REF_URL}`);
throw new Error('script is not supported in NestedAggregation');
}
/**
* Sets the nested path
*
* @param {string} path `path` of the nested document
* @returns {NestedAggregation} returns `this` so that calls can be chained
*/
path(path) {
this._aggsDef.path = path;
return this;
}
}
module.exports = NestedAggregation;