feat: make backend work with automatically generated aggregations

This commit is contained in:
Wieland Schöbl
2019-09-23 12:58:38 +02:00
committed by Rainer Killinger
parent 496e6c5bd0
commit ba2c6f655c
8 changed files with 128 additions and 141 deletions

View File

@@ -15,6 +15,12 @@
*/
import {SCThingType} from '@openstapps/core';
import {SCThing} from '@openstapps/core';
import {
ESAggMatchAllFilter,
ESAggTypeFilter,
ESNestedAggregation,
ESTermsFilter,
} from '@openstapps/core-tools/lib/mappings/aggregation-definitions';
import {NameList} from 'elasticsearch';
/**
@@ -88,14 +94,6 @@ export function isNestedAggregation(agg: BucketAggregation | NestedAggregation):
return typeof (agg as BucketAggregation).buckets === 'undefined';
}
/**
* An elasticsearch bucket aggregation
* @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket.html
*/
export interface AggregationSchema {
[aggregationName: string]: ESTermsFilter | ESNestedAggregation;
}
/**
* A configuration for using the Dis Max Query
*
@@ -275,26 +273,6 @@ export interface ESTermFilter {
};
}
/**
* An elasticsearch terms filter
*/
export interface ESTermsFilter {
/**
* Terms filter definition
*/
terms: {
/**
* Field to apply filter to
*/
field: string;
/**
* Number of results
*/
size?: number;
};
}
/**
* Checks if the parameter is of type ESTermsFilter
* @param agg the value to check
@@ -303,30 +281,6 @@ export function isESTermsFilter(agg: ESTermsFilter | ESNestedAggregation): agg i
return typeof (agg as ESTermsFilter).terms !== 'undefined';
}
/**
* For nested aggregations
*/
export interface ESNestedAggregation {
/**
* Possible nested Aggregations
*/
aggs: AggregationSchema;
/**
* Possible filter for types
*/
filter: {
/**
* The type of the object to find
*/
type: {
/**
* The name of the type
*/
value: SCThingType;
};
};
}
/**
* Checks if the parameter is of type ESTermsFilter
* @param agg the value to check
@@ -335,6 +289,15 @@ export function isESNestedAggregation(agg: ESTermsFilter | ESNestedAggregation):
return typeof (agg as ESNestedAggregation).aggs !== 'undefined';
}
/**
* Checks if the parameter is of type
*
* @param filter the filter to narrow the type of
*/
export function isESAggMatchAllFilter(filter: ESAggTypeFilter | ESAggMatchAllFilter): filter is ESAggMatchAllFilter {
return filter.hasOwnProperty('match_all');
}
/**
* An elasticsearch type filter
*/
@@ -358,6 +321,7 @@ export interface ESGeoDistanceFilterArguments {
* The radius of the circle centred on the specified location
*/
distance: string;
[fieldName: string]: {
/**
* Latitute
@@ -412,9 +376,9 @@ export interface ESBooleanFilterArguments<T> {
* An elasticsearch boolean filter
*/
export interface ESBooleanFilter<T> {
/**
* @see ESBooleanFilterArguments
*/
/**
* @see ESBooleanFilterArguments
*/
bool: ESBooleanFilterArguments<T>;
}
@@ -485,6 +449,7 @@ export interface ESGeoDistanceSortArguments {
* Value unit
*/
unit: 'm';
[field: string]: {
/**
* Latitute
@@ -512,9 +477,9 @@ export interface ESGeoDistanceSort {
* An elasticsearch script sort
*/
export interface ScriptSort {
/**
* A script
*/
/**
* A script
*/
_script: {
/**
* Order