Skip to content

Commit 9d2adf8

Browse files
committed
wip(Aggs): Described all Bucket aggregations
1 parent ca9f771 commit 9d2adf8

16 files changed

+422
-9
lines changed

src/ElasticDSL/Aggs/AggRules.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,25 @@ import { getSumITC } from './Metrics/Sum';
1919
import { getTopHitsITC } from './Metrics/TopHits';
2020
import { getValueCountITC } from './Metrics/ValueCount';
2121

22+
import { getChildrenITC } from './Bucket/Children';
23+
import { getDateHistogramITC } from './Bucket/DateHistogram';
24+
import { getDateRangeITC } from './Bucket/DateRange';
25+
import { getDiversifiedSamplerITC } from './Bucket/DiversifiedSampler';
26+
import { getFilterITC } from './Bucket/Filter';
27+
import { getFiltersITC } from './Bucket/Filters';
28+
import { getGeoDistanceITC } from './Bucket/GeoDistance';
29+
import { getGeohashGridITC } from './Bucket/GeohashGrid';
30+
import { getGlobalITC } from './Bucket/Global';
31+
import { getHistogramITC } from './Bucket/Histogram';
32+
import { getIpRangeITC } from './Bucket/IpRange';
33+
import { getMissingITC } from './Bucket/Missing';
34+
import { getNestedITC } from './Bucket/Nested';
35+
import { getRangeITC } from './Bucket/Range';
36+
import { getReverseNestedITC } from './Bucket/ReverseNested';
37+
import { getSamplerITC } from './Bucket/Sampler';
38+
import { getSignificantTermsITC } from './Bucket/SignificantTerms';
39+
import { getTermsITC } from './Bucket/Terms';
40+
2241
export function getAggRulesITC(opts: mixed = {}): InputTypeComposer {
2342
const name = getTypeName('AggRules', opts);
2443
const description = desc(
@@ -51,6 +70,25 @@ export function getAggRulesITC(opts: mixed = {}): InputTypeComposer {
5170
top_hits: () => getTopHitsITC(opts),
5271
value_count: () => getValueCountITC(opts),
5372

73+
children: () => getChildrenITC(opts),
74+
date_histogram: () => getDateHistogramITC(opts),
75+
date_range: () => getDateRangeITC(opts),
76+
diversified_sampler: () => getDiversifiedSamplerITC(opts),
77+
filter: () => getFilterITC(opts),
78+
filters: () => getFiltersITC(opts),
79+
geo_distance: () => getGeoDistanceITC(opts),
80+
geohash_grid: () => getGeohashGridITC(opts),
81+
global: () => getGlobalITC(opts),
82+
histogram: () => getHistogramITC(opts),
83+
ip_range: () => getIpRangeITC(opts),
84+
missing: () => getMissingITC(opts),
85+
nested: () => getNestedITC(opts),
86+
range: () => getRangeITC(opts),
87+
reverse_nested: () => getReverseNestedITC(opts),
88+
sampler: () => getSamplerITC(opts),
89+
significant_terms: () => getSignificantTermsITC(opts),
90+
terms: () => getTermsITC(opts),
91+
5492
aggs: {
5593
type: () => [getAggBlockITC(opts)],
5694
description: 'Aggregation block',

src/ElasticDSL/Aggs/Bucket/DateRange.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ export function getDateRangeITC(opts: mixed = {}): InputTypeComposer {
88
const name = getTypeName('AggsDateRange', opts);
99
const description = desc(
1010
`
11-
A range aggregation that is dedicated for date values. The main difference
12-
between this aggregation and the normal range aggregation is that
13-
the from and to values can be expressed in Date Math expressions,
11+
A range aggregation that is dedicated for date values.
12+
The \`from\` and \`to\` values can be expressed in Date Math expressions,
1413
and it is also possible to specify a date format by which the from
15-
and to response fields will be returned. Note that this aggregation
16-
includes the from value and excludes the to value for each range.
14+
and to response fields will be returned.
15+
Note that this aggregation includes the \`from\` value and excludes the
16+
\`to\` value for each range.
1717
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html)
1818
`
1919
);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* @flow */
2+
3+
import { InputTypeComposer } from 'graphql-compose';
4+
import { getTypeName, getOrSetType, desc } from '../../../utils';
5+
6+
export function getGeohashGridITC(opts: mixed = {}): InputTypeComposer {
7+
const name = getTypeName('AggsGeohashGrid', opts);
8+
const description = desc(
9+
`
10+
A multi-bucket aggregation that works on geo_point fields and groups points
11+
into buckets that represent cells in a grid. Each cell is labeled using
12+
a geohash which is of user-definable precision. Geohashes can have a choice
13+
of precision between 1 and 12.
14+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geohashgrid-aggregation.html)
15+
`
16+
);
17+
18+
return getOrSetType(name, () =>
19+
// $FlowFixMe
20+
InputTypeComposer.create({
21+
name,
22+
description,
23+
fields: {
24+
field: 'String',
25+
precision: 'Int',
26+
size: {
27+
type: 'Int',
28+
defaultValue: 10000,
29+
},
30+
shard_size: 'Int',
31+
},
32+
}));
33+
}

src/ElasticDSL/Aggs/Bucket/Global.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* @flow */
2+
3+
import { InputTypeComposer } from 'graphql-compose';
4+
import { getTypeName, getOrSetType, desc } from '../../../utils';
5+
6+
export function getGlobalITC(opts: mixed = {}): InputTypeComposer {
7+
const name = getTypeName('AggsGlobal', opts);
8+
const description = desc(
9+
`
10+
Defines a single bucket of all the documents within the search execution
11+
context. This context is defined by the indices and the document types
12+
you’re searching on, but is not influenced by the search query itself.
13+
Should have empty body, without fields, eg. \`global: {}\`
14+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-global-aggregation.html)
15+
`
16+
);
17+
18+
return getOrSetType(name, () =>
19+
// $FlowFixMe
20+
InputTypeComposer.create({
21+
name,
22+
description,
23+
fields: {
24+
without_fields: 'JSON',
25+
},
26+
}));
27+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* @flow */
2+
3+
import { InputTypeComposer } from 'graphql-compose';
4+
import { getTypeName, getOrSetType, desc } from '../../../utils';
5+
6+
export function getHistogramITC(opts: mixed = {}): InputTypeComposer {
7+
const name = getTypeName('AggsHistogram', opts);
8+
const description = desc(
9+
`
10+
A multi-bucket values source based aggregation that can be applied on
11+
numeric values extracted from the documents. It dynamically builds fixed
12+
size (a.k.a. interval) buckets over the values.
13+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html)
14+
`
15+
);
16+
17+
return getOrSetType(name, () =>
18+
// $FlowFixMe
19+
InputTypeComposer.create({
20+
name,
21+
description,
22+
fields: {
23+
field: 'String',
24+
interval: 'Float',
25+
missing: 'Float',
26+
min_doc_count: 'Int',
27+
extended_bounds: `input ${getTypeName('AggsHistogramBounds', opts)} {
28+
min: Float
29+
max: Float
30+
}`,
31+
order: 'JSON',
32+
offset: 'Int',
33+
keyed: 'Boolean',
34+
},
35+
}));
36+
}

src/ElasticDSL/Aggs/Bucket/IpRange.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* @flow */
2+
3+
import { InputTypeComposer } from 'graphql-compose';
4+
import { getTypeName, getOrSetType, desc } from '../../../utils';
5+
import { getIpRangeTypeITC } from '../../Commons/Ip';
6+
7+
export function getIpRangeITC(opts: mixed = {}): InputTypeComposer {
8+
const name = getTypeName('AggsIpRange', opts);
9+
const description = desc(
10+
`
11+
A range aggregation that is dedicated for IP values.
12+
Note that this aggregation includes the \`from\` value and excludes the
13+
\`to\` value for each range.
14+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-iprange-aggregation.html)
15+
`
16+
);
17+
18+
return getOrSetType(name, () =>
19+
// $FlowFixMe
20+
InputTypeComposer.create({
21+
name,
22+
description,
23+
fields: {
24+
field: 'String',
25+
ranges: () => [getIpRangeTypeITC(opts)],
26+
},
27+
}));
28+
}

src/ElasticDSL/Aggs/Bucket/Missing.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* @flow */
2+
3+
import { InputTypeComposer } from 'graphql-compose';
4+
import { getTypeName, getOrSetType, desc } from '../../../utils';
5+
6+
export function getMissingITC(opts: mixed = {}): InputTypeComposer {
7+
const name = getTypeName('AggsMissing', opts);
8+
const description = desc(
9+
`
10+
A field data based single bucket aggregation, that creates a bucket of all
11+
documents in the current document set context that are missing a field
12+
value (effectively, missing a field or having the configured NULL value set).
13+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-missing-aggregation.html)
14+
`
15+
);
16+
17+
return getOrSetType(name, () =>
18+
// $FlowFixMe
19+
InputTypeComposer.create({
20+
name,
21+
description,
22+
fields: {
23+
field: 'String',
24+
},
25+
}));
26+
}

src/ElasticDSL/Aggs/Bucket/Nested.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* @flow */
2+
3+
import { InputTypeComposer } from 'graphql-compose';
4+
import { getTypeName, getOrSetType, desc } from '../../../utils';
5+
6+
export function getNestedITC(opts: mixed = {}): InputTypeComposer {
7+
const name = getTypeName('AggsNested', opts);
8+
const description = desc(
9+
`
10+
A special single bucket aggregation that enables aggregating nested documents.
11+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html)
12+
`
13+
);
14+
15+
return getOrSetType(name, () =>
16+
// $FlowFixMe
17+
InputTypeComposer.create({
18+
name,
19+
description,
20+
fields: {
21+
path: 'String',
22+
},
23+
}));
24+
}

src/ElasticDSL/Aggs/Bucket/Range.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* @flow */
2+
3+
import { InputTypeComposer } from 'graphql-compose';
4+
import { getTypeName, getOrSetType, desc } from '../../../utils';
5+
import { getFloatRangeKeyedITC } from '../../Commons/Float';
6+
import { getCommonsScriptITC } from '../../Commons/Script';
7+
8+
export function getRangeITC(opts: mixed = {}): InputTypeComposer {
9+
const name = getTypeName('AggsRange', opts);
10+
const description = desc(
11+
`
12+
A multi-bucket value source based aggregation that enables the user
13+
to define a set of ranges - each representing a bucket.
14+
Note that this aggregation includes the \`from\` value and excludes the
15+
\`to\` value for each range.
16+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-range-aggregation.html)
17+
`
18+
);
19+
20+
return getOrSetType(name, () =>
21+
// $FlowFixMe
22+
InputTypeComposer.create({
23+
name,
24+
description,
25+
fields: {
26+
field: 'String',
27+
ranges: () => [getFloatRangeKeyedITC(opts)],
28+
keyed: 'Boolean',
29+
script: () => getCommonsScriptITC(opts),
30+
},
31+
}));
32+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* @flow */
2+
3+
import { InputTypeComposer } from 'graphql-compose';
4+
import { getTypeName, getOrSetType, desc } from '../../../utils';
5+
6+
export function getReverseNestedITC(opts: mixed = {}): InputTypeComposer {
7+
const name = getTypeName('AggsReverseNested', opts);
8+
const description = desc(
9+
`
10+
A special single bucket aggregation that enables aggregating on parent docs
11+
from nested documents.
12+
The \`reverse_nested\` aggregation must be defined inside a \`nested\` aggregation.
13+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html)
14+
`
15+
);
16+
17+
return getOrSetType(name, () =>
18+
// $FlowFixMe
19+
InputTypeComposer.create({
20+
name,
21+
description,
22+
fields: {
23+
path: 'String',
24+
},
25+
}));
26+
}

src/ElasticDSL/Aggs/Bucket/Sampler.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* @flow */
2+
3+
import { InputTypeComposer } from 'graphql-compose';
4+
import { getTypeName, getOrSetType, desc } from '../../../utils';
5+
6+
export function getSamplerITC(opts: mixed = {}): InputTypeComposer {
7+
const name = getTypeName('AggsSampler', opts);
8+
const description = desc(
9+
`
10+
A filtering aggregation used to limit any sub aggregations' processing
11+
to a sample of the top-scoring documents.
12+
Tightening the focus of analytics to high-relevance matches rather than
13+
the potentially very long tail of low-quality matches.
14+
This functionality is experimental and may be changed or removed completely.
15+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-sampler-aggregation.html)
16+
`
17+
);
18+
19+
return getOrSetType(name, () =>
20+
// $FlowFixMe
21+
InputTypeComposer.create({
22+
name,
23+
description,
24+
fields: {
25+
shard_size: 'Int',
26+
},
27+
}));
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* @flow */
2+
3+
import { InputTypeComposer } from 'graphql-compose';
4+
import { getTypeName, getOrSetType, desc } from '../../../utils';
5+
6+
export function getSignificantTermsITC(opts: mixed = {}): InputTypeComposer {
7+
const name = getTypeName('AggsSignificantTerms', opts);
8+
const description = desc(
9+
`
10+
An aggregation that returns interesting or unusual occurrences of terms in a set.
11+
The significant_terms aggregation can be very heavy when run on large indices.
12+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html)
13+
`
14+
);
15+
16+
return getOrSetType(name, () =>
17+
// $FlowFixMe
18+
InputTypeComposer.create({
19+
name,
20+
description,
21+
fields: {
22+
field: 'String',
23+
min_doc_count: 'Int',
24+
background_filter: 'JSON',
25+
execution_hint: 'String',
26+
},
27+
}));
28+
}

0 commit comments

Comments
 (0)