Skip to content

Commit ca9f771

Browse files
committed
wip(Aggs): Described all metrics and started bucket aggregations.
1 parent 42f5822 commit ca9f771

30 files changed

+830
-77
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"babel-eslint": "^7.1.1",
3636
"babel-plugin-transform-flow-strip-types": "^6.22.0",
3737
"babel-plugin-transform-object-rest-spread": "^6.22.0",
38-
"babel-preset-env": "^1.2.1",
38+
"babel-preset-env": "^1.2.2",
3939
"cz-conventional-changelog": "^2.0.0",
4040
"elasticsearch": "^12.1.3",
4141
"eslint": "^3.17.1",
@@ -48,7 +48,7 @@
4848
"express-graphql": "^0.6.3",
4949
"flow-bin": "^0.41.0",
5050
"graphql": "^0.9.1",
51-
"graphql-compose": "^1.17.1",
51+
"graphql-compose": "^1.17.2",
5252
"jest": "^19.0.2",
5353
"jest-babel": "^1.0.1",
5454
"npm-run-all": "^4.0.1",

src/ElasticDSL/Aggs/AggRules.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ import { getAggBlockITC } from './AggBlock';
77
import { getAvgITC } from './Metrics/Avg';
88
import { getCardinalityITC } from './Metrics/Cardinality';
99
import { getExtendedStatsITC } from './Metrics/ExtendedStats';
10+
import { getGeoBoundsITC } from './Metrics/GeoBounds';
11+
import { getGeoCentroidITC } from './Metrics/GeoCentroid';
12+
import { getMaxITC } from './Metrics/Max';
13+
import { getMinITC } from './Metrics/Min';
14+
import { getPercentileRanksITC } from './Metrics/PercentileRanks';
15+
import { getPercentilesITC } from './Metrics/Percentiles';
16+
import { getScriptedMetricITC } from './Metrics/ScriptedMetric';
17+
import { getStatsITC } from './Metrics/Stats';
18+
import { getSumITC } from './Metrics/Sum';
19+
import { getTopHitsITC } from './Metrics/TopHits';
20+
import { getValueCountITC } from './Metrics/ValueCount';
1021

1122
export function getAggRulesITC(opts: mixed = {}): InputTypeComposer {
1223
const name = getTypeName('AggRules', opts);
@@ -28,6 +39,17 @@ export function getAggRulesITC(opts: mixed = {}): InputTypeComposer {
2839
avg: () => getAvgITC(opts),
2940
cardinality: () => getCardinalityITC(opts),
3041
extended_stats: () => getExtendedStatsITC(opts),
42+
geo_bounds: () => getGeoBoundsITC(opts),
43+
geo_centroid: () => getGeoCentroidITC(opts),
44+
max: () => getMaxITC(opts),
45+
min: () => getMinITC(opts),
46+
percentile_ranks: () => getPercentileRanksITC(opts),
47+
percentiles: () => getPercentilesITC(opts),
48+
scripted_metric: () => getScriptedMetricITC(opts),
49+
stats: () => getStatsITC(opts),
50+
sum: () => getSumITC(opts),
51+
top_hits: () => getTopHitsITC(opts),
52+
value_count: () => getValueCountITC(opts),
3153

3254
aggs: {
3355
type: () => [getAggBlockITC(opts)],
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* @flow */
2+
3+
import { InputTypeComposer } from 'graphql-compose';
4+
import { getTypeName, getOrSetType, desc } from '../../../utils';
5+
6+
export function getChildrenITC(opts: mixed = {}): InputTypeComposer {
7+
const name = getTypeName('AggsChildren', opts);
8+
const description = desc(
9+
`
10+
A special single bucket aggregation that enables aggregating from buckets
11+
on parent document types to buckets on child documents.
12+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-children-aggregation.html)
13+
`
14+
);
15+
16+
return getOrSetType(name, () =>
17+
// $FlowFixMe
18+
InputTypeComposer.create({
19+
name,
20+
description,
21+
fields: {
22+
type: 'String',
23+
},
24+
}));
25+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* @flow */
2+
3+
import { InputTypeComposer } from 'graphql-compose';
4+
import { getTypeName, getOrSetType, desc } from '../../../utils';
5+
import { getCommonsScriptITC } from '../../Commons/Script';
6+
import {
7+
getDateIntervalFC,
8+
getDateFormatFC,
9+
getDateTimeZoneFC,
10+
} from '../../Commons/Date';
11+
12+
export function getDateHistogramITC(opts: mixed = {}): InputTypeComposer {
13+
const name = getTypeName('AggsDateHistogram', opts);
14+
const description = desc(
15+
`
16+
A multi-bucket aggregation similar to the histogram except it can only
17+
be applied on date values.
18+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html)
19+
`
20+
);
21+
22+
return getOrSetType(name, () =>
23+
// $FlowFixMe
24+
InputTypeComposer.create({
25+
name,
26+
description,
27+
fields: {
28+
field: 'String',
29+
interval: getDateIntervalFC(opts),
30+
time_zone: getDateTimeZoneFC(opts),
31+
offset: getDateIntervalFC(opts),
32+
format: getDateFormatFC(opts),
33+
missing: 'Float',
34+
script: () => getCommonsScriptITC(opts),
35+
},
36+
}));
37+
}
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+
import { getDateFormatFC, getDateTimeZoneFC } from '../../Commons/Date';
6+
7+
export function getDateRangeITC(opts: mixed = {}): InputTypeComposer {
8+
const name = getTypeName('AggsDateRange', opts);
9+
const description = desc(
10+
`
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,
14+
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.
17+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html)
18+
`
19+
);
20+
21+
return getOrSetType(name, () =>
22+
// $FlowFixMe
23+
InputTypeComposer.create({
24+
name,
25+
description,
26+
fields: {
27+
field: 'String',
28+
format: getDateFormatFC(opts),
29+
ranges: () => [getDateRangeITC(opts)],
30+
time_zone: getDateTimeZoneFC(opts),
31+
},
32+
}));
33+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* @flow */
2+
3+
import { InputTypeComposer } from 'graphql-compose';
4+
import { getTypeName, getOrSetType, desc } from '../../../utils';
5+
import { getCommonsScriptITC } from '../../Commons/Script';
6+
7+
export function getDiversifiedSamplerITC(opts: mixed = {}): InputTypeComposer {
8+
const name = getTypeName('AggsDiversifiedSampler', opts);
9+
const description = desc(
10+
`
11+
A filtering aggregation used to limit any sub aggregations' processing to
12+
a sample of the top-scoring documents. Diversity settings are used to
13+
limit the number of matches that share a common value such as an "author".
14+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-diversified-sampler-aggregation.html)
15+
`
16+
);
17+
18+
return getOrSetType(name, () =>
19+
// $FlowFixMe
20+
InputTypeComposer.create({
21+
name,
22+
description,
23+
fields: {
24+
shard_size: {
25+
type: 'String',
26+
defaultValue: 100,
27+
},
28+
field: 'String',
29+
max_docs_per_value: 'Int',
30+
script: () => getCommonsScriptITC(opts),
31+
execution_hint: 'String',
32+
},
33+
}));
34+
}

src/ElasticDSL/Aggs/Bucket/Filter.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* @flow */
2+
/* eslint-disable no-unused-vars */
3+
4+
import { InputTypeComposer } from 'graphql-compose';
5+
import { getTypeName, getOrSetType, desc } from '../../../utils';
6+
import { getQueryITC } from '../../Query/Query';
7+
8+
export function getFilterITC(opts: mixed = {}): InputTypeComposer {
9+
const name = getTypeName('AggsFilter', opts);
10+
const description = desc(
11+
`
12+
Defines a single bucket of all the documents in the current document set
13+
context that match a specified filter. Often this will be used to narrow
14+
down the current aggregation context to a specific set of documents.
15+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html)
16+
`
17+
);
18+
19+
return getQueryITC(opts);
20+
}

src/ElasticDSL/Aggs/Bucket/Filters.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 getFiltersITC(opts: mixed = {}): InputTypeComposer {
7+
const name = getTypeName('AggsFilters', opts);
8+
const description = desc(
9+
`
10+
Defines a multi bucket aggregation where each bucket is associated
11+
with a filter. Each bucket will collect all documents that match
12+
its associated filter.
13+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filters-aggregation.html)
14+
`
15+
);
16+
17+
return getOrSetType(name, () =>
18+
// $FlowFixMe
19+
InputTypeComposer.create({
20+
name,
21+
description,
22+
fields: {
23+
filters: 'JSON',
24+
other_bucket: 'Boolean',
25+
other_bucket_key: 'String',
26+
},
27+
}));
28+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* @flow */
2+
3+
import { InputTypeComposer } from 'graphql-compose';
4+
import { getTypeName, getOrSetType, desc } from '../../../utils';
5+
import {
6+
getGeoPointFC,
7+
getDistanceUnitFC,
8+
getDistanceCalculationModeFC,
9+
} from '../../Commons/Geo';
10+
import { getFloatRangeITC } from '../../Commons/Float';
11+
12+
export function getGeoDistanceITC(opts: mixed = {}): InputTypeComposer {
13+
const name = getTypeName('AggsGeoDistance', opts);
14+
const description = desc(
15+
`
16+
A multi-bucket aggregation that works on geo_point fields. The user can
17+
define a point of origin and a set of distance range buckets.
18+
The aggregation evaluate the distance of each document value from the
19+
origin point and determines the buckets it belongs to based on the ranges
20+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geodistance-aggregation.html)
21+
`
22+
);
23+
24+
return getOrSetType(name, () =>
25+
// $FlowFixMe
26+
InputTypeComposer.create({
27+
name,
28+
description,
29+
fields: {
30+
field: 'String',
31+
origin: getGeoPointFC(opts),
32+
ranges: [getFloatRangeITC(opts)],
33+
unit: getDistanceUnitFC(opts),
34+
distance_type: getDistanceCalculationModeFC(opts),
35+
},
36+
}));
37+
}

src/ElasticDSL/Aggs/Metrics/Avg.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function getAvgITC(opts: mixed = {}): InputTypeComposer {
2222
fields: {
2323
field: 'String',
2424
missing: 'Float',
25-
script: () => getCommonsScriptITC(),
25+
script: () => getCommonsScriptITC(opts),
2626
},
2727
})
2828
);

src/ElasticDSL/Aggs/Metrics/Cardinality.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function getCardinalityITC(opts: mixed = {}): InputTypeComposer {
3333
),
3434
},
3535
missing: 'String',
36-
script: () => getCommonsScriptITC(),
36+
script: () => getCommonsScriptITC(opts),
3737
},
3838
}));
3939
}

src/ElasticDSL/Aggs/Metrics/ExtendedStats.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function getExtendedStatsITC(opts: mixed = {}): InputTypeComposer {
2525
field: 'String',
2626
sigma: 'Float',
2727
missing: 'Float',
28-
script: () => getCommonsScriptITC(),
28+
script: () => getCommonsScriptITC(opts),
2929
},
3030
}));
3131
}
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 getGeoBoundsITC(opts: mixed = {}): InputTypeComposer {
7+
const name = getTypeName('AggsGeoBounds', opts);
8+
const description = desc(
9+
`
10+
A metric aggregation that computes the bounding box containing
11+
all geo_point values for a field.
12+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-geobounds-aggregation.html)
13+
`
14+
);
15+
16+
return getOrSetType(name, () =>
17+
// $FlowFixMe
18+
InputTypeComposer.create({
19+
name,
20+
description,
21+
fields: {
22+
field: 'String!',
23+
wrap_longitude: 'Boolean',
24+
},
25+
}));
26+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* @flow */
2+
3+
import { InputTypeComposer } from 'graphql-compose';
4+
import { getTypeName, getOrSetType, desc } from '../../../utils';
5+
6+
export function getGeoCentroidITC(opts: mixed = {}): InputTypeComposer {
7+
const name = getTypeName('AggsGeoCentroid', opts);
8+
const description = desc(
9+
`
10+
A metric aggregation that computes the weighted centroid from all coordinate
11+
values for a Geo-point datatype field.
12+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-geocentroid-aggregation.html)
13+
`
14+
);
15+
16+
return getOrSetType(name, () =>
17+
// $FlowFixMe
18+
InputTypeComposer.create({
19+
name,
20+
description,
21+
fields: {
22+
field: 'String!',
23+
},
24+
}));
25+
}

src/ElasticDSL/Aggs/Metrics/Max.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* @flow */
2+
3+
import { InputTypeComposer } from 'graphql-compose';
4+
import { getTypeName, getOrSetType, desc } from '../../../utils';
5+
import { getCommonsScriptITC } from '../../Commons/Script';
6+
7+
export function getMaxITC(opts: mixed = {}): InputTypeComposer {
8+
const name = getTypeName('AggsMax', opts);
9+
const description = desc(
10+
`
11+
A single-value metrics aggregation that keeps track and returns the maximum
12+
value among the numeric values extracted from the aggregated documents.
13+
These values can be extracted either from specific numeric fields
14+
in the documents, or be generated by a provided script.
15+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-max-aggregation.html)
16+
`
17+
);
18+
19+
return getOrSetType(name, () =>
20+
// $FlowFixMe
21+
InputTypeComposer.create({
22+
name,
23+
description,
24+
fields: {
25+
field: 'String',
26+
missing: 'Float',
27+
script: () => getCommonsScriptITC(opts),
28+
},
29+
}));
30+
}

0 commit comments

Comments
 (0)