mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 09:03:02 +00:00
feat: update to of elasticsearch 8.4
This commit is contained in:
committed by
Rainer Killinger
parent
515a6eeea5
commit
c9b83b5d71
@@ -25,25 +25,14 @@ import {
|
||||
SCThingType,
|
||||
} from '@openstapps/core';
|
||||
import {expect} from 'chai';
|
||||
import {
|
||||
ESDateRangeFilter,
|
||||
ESRangeFilter,
|
||||
ESNumericRangeFilter,
|
||||
ElasticsearchConfig,
|
||||
ESBooleanFilter,
|
||||
ESGenericSort,
|
||||
ESGeoDistanceFilter,
|
||||
ESGeoDistanceSort,
|
||||
ESTermFilter,
|
||||
ScriptSort,
|
||||
} from '../../../src/storage/elasticsearch/types/elasticsearch';
|
||||
import {buildFilter} from '../../../src/storage/elasticsearch/query/filter';
|
||||
import {buildBooleanFilter} from '../../../src/storage/elasticsearch/query/filters/boolean';
|
||||
import {buildQuery} from '../../../src/storage/elasticsearch/query/query';
|
||||
import {buildSort} from '../../../src/storage/elasticsearch/query/sort';
|
||||
import {ElasticsearchConfig} from '../../../src/storage/elasticsearch/types/elasticsearch-config';
|
||||
import {QueryDslSpecificQueryContainer} from '../../../src/storage/elasticsearch/types/util';
|
||||
import {configFile} from '../../../src/common';
|
||||
import {
|
||||
buildBooleanFilter,
|
||||
buildFilter,
|
||||
buildQuery,
|
||||
buildSort,
|
||||
} from '../../../src/storage/elasticsearch/query';
|
||||
import {SortCombinations} from '@elastic/elasticsearch/lib/api/types';
|
||||
|
||||
describe('Query', function () {
|
||||
describe('buildBooleanFilter', function () {
|
||||
@@ -74,7 +63,7 @@ describe('Query', function () {
|
||||
or: {...booleanFilter, arguments: {...booleanFilter.arguments, operation: 'or'}},
|
||||
not: {...booleanFilter, arguments: {...booleanFilter.arguments, operation: 'not'}},
|
||||
};
|
||||
const expectedEsFilters: Array<ESTermFilter> = [
|
||||
const expectedEsFilters: Array<QueryDslSpecificQueryContainer<'term'>> = [
|
||||
{
|
||||
term: {
|
||||
'type.raw': 'catalog',
|
||||
@@ -88,20 +77,20 @@ describe('Query', function () {
|
||||
];
|
||||
|
||||
it('should create appropriate elasticsearch "and" filter argument', function () {
|
||||
const {must} = buildBooleanFilter(booleanFilters.and);
|
||||
const {must} = buildBooleanFilter(booleanFilters.and).bool;
|
||||
|
||||
expect(must).to.be.eql(expectedEsFilters);
|
||||
});
|
||||
|
||||
it('should create appropriate elasticsearch "or" filter argument', function () {
|
||||
const {should, minimum_should_match} = buildBooleanFilter(booleanFilters.or);
|
||||
const {should, minimum_should_match} = buildBooleanFilter(booleanFilters.or).bool;
|
||||
|
||||
expect(should).to.be.eql(expectedEsFilters);
|
||||
expect(minimum_should_match).to.be.equal(1);
|
||||
});
|
||||
|
||||
it('should create appropriate elasticsearch "not" filter argument', function () {
|
||||
const {must_not} = buildBooleanFilter(booleanFilters.not);
|
||||
const {must_not} = buildBooleanFilter(booleanFilters.not).bool;
|
||||
|
||||
expect(must_not).to.be.eql(expectedEsFilters);
|
||||
});
|
||||
@@ -196,6 +185,10 @@ describe('Query', function () {
|
||||
|
||||
expect(() => buildQuery(parameters, config, esConfig)).to.throw('query type');
|
||||
});
|
||||
|
||||
it('should accept other search contexts', function () {
|
||||
expect(buildQuery({context: 'place', ...parameters}, config, esConfig)).to.be.an('object');
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildFilter', function () {
|
||||
@@ -267,7 +260,7 @@ describe('Query', function () {
|
||||
|
||||
it('should build value filter', function () {
|
||||
const filter = buildFilter(searchFilters.value);
|
||||
const expectedFilter: ESTermFilter = {
|
||||
const expectedFilter: QueryDslSpecificQueryContainer<'term'> = {
|
||||
term: {
|
||||
'type.raw': SCThingType.Dish,
|
||||
},
|
||||
@@ -279,7 +272,7 @@ describe('Query', function () {
|
||||
it('should build numeric range filters', function () {
|
||||
for (const upperMode of ['inclusive', 'exclusive', null]) {
|
||||
for (const lowerMode of ['inclusive', 'exclusive', null]) {
|
||||
const expectedFilter: ESNumericRangeFilter = {
|
||||
const expectedFilter: QueryDslSpecificQueryContainer<'range'> = {
|
||||
range: {
|
||||
price: {
|
||||
relation: undefined,
|
||||
@@ -304,7 +297,7 @@ describe('Query', function () {
|
||||
mode: bound as 'inclusive' | 'exclusive',
|
||||
limit: out,
|
||||
};
|
||||
expectedFilter.range.price[
|
||||
expectedFilter.range.price![
|
||||
`${location === 'lowerBound' ? 'g' : 'l'}${bound === 'inclusive' ? 'te' : 't'}`
|
||||
] = out;
|
||||
}
|
||||
@@ -312,7 +305,7 @@ describe('Query', function () {
|
||||
setBound('upperBound', upperMode);
|
||||
setBound('lowerBound', lowerMode);
|
||||
|
||||
const filter = buildFilter(rawFilter) as ESNumericRangeFilter;
|
||||
const filter = buildFilter(rawFilter) as QueryDslSpecificQueryContainer<'term'>;
|
||||
expect(filter).to.deep.equal(expectedFilter);
|
||||
for (const bound of ['g', 'l']) {
|
||||
// @ts-expect-error implicit any
|
||||
@@ -330,7 +323,7 @@ describe('Query', function () {
|
||||
it('should build date range filters', function () {
|
||||
for (const upperMode of ['inclusive', 'exclusive', null]) {
|
||||
for (const lowerMode of ['inclusive', 'exclusive', null]) {
|
||||
const expectedFilter: ESDateRangeFilter = {
|
||||
const expectedFilter: QueryDslSpecificQueryContainer<'range'> = {
|
||||
range: {
|
||||
price: {
|
||||
format: 'thisIsADummyFormat',
|
||||
@@ -359,7 +352,7 @@ describe('Query', function () {
|
||||
mode: bound as 'inclusive' | 'exclusive',
|
||||
limit: out,
|
||||
};
|
||||
expectedFilter.range.price[
|
||||
expectedFilter.range.price![
|
||||
`${location === 'lowerBound' ? 'g' : 'l'}${bound === 'inclusive' ? 'te' : 't'}`
|
||||
] = out;
|
||||
}
|
||||
@@ -367,7 +360,7 @@ describe('Query', function () {
|
||||
setBound('upperBound', upperMode);
|
||||
setBound('lowerBound', lowerMode);
|
||||
|
||||
const filter = buildFilter(rawFilter) as ESNumericRangeFilter;
|
||||
const filter = buildFilter(rawFilter) as QueryDslSpecificQueryContainer<'range'>;
|
||||
expect(filter).to.deep.equal(expectedFilter);
|
||||
for (const bound of ['g', 'l']) {
|
||||
// @ts-expect-error implicit any
|
||||
@@ -394,7 +387,7 @@ describe('Query', function () {
|
||||
},
|
||||
});
|
||||
|
||||
const expectedFilter: ESRangeFilter = {
|
||||
const expectedFilter: QueryDslSpecificQueryContainer<'range'> = {
|
||||
range: {
|
||||
'offers.availabilityRange': {
|
||||
gte: `test||/${scope}`,
|
||||
@@ -415,7 +408,7 @@ describe('Query', function () {
|
||||
},
|
||||
});
|
||||
|
||||
const expectedFilter: ESRangeFilter = {
|
||||
const expectedFilter: QueryDslSpecificQueryContainer<'range'> = {
|
||||
range: {
|
||||
'offers.availabilityRange': {
|
||||
gte: 'test||/s',
|
||||
@@ -436,7 +429,7 @@ describe('Query', function () {
|
||||
},
|
||||
});
|
||||
|
||||
const expectedFilter: ESRangeFilter = {
|
||||
const expectedFilter: QueryDslSpecificQueryContainer<'range'> = {
|
||||
range: {
|
||||
'offers.availabilityRange': {
|
||||
gte: `test||/d`,
|
||||
@@ -456,7 +449,7 @@ describe('Query', function () {
|
||||
},
|
||||
});
|
||||
|
||||
const expectedFilter: ESRangeFilter = {
|
||||
const expectedFilter: QueryDslSpecificQueryContainer<'range'> = {
|
||||
range: {
|
||||
'offers.availabilityRange': {
|
||||
gte: `now/d`,
|
||||
@@ -470,7 +463,7 @@ describe('Query', function () {
|
||||
|
||||
it('should build distance filter', function () {
|
||||
const filter = buildFilter(searchFilters.distance);
|
||||
const expectedFilter: ESGeoDistanceFilter = {
|
||||
const expectedFilter: QueryDslSpecificQueryContainer<'geo_distance'> = {
|
||||
geo_distance: {
|
||||
'distance': '1000m',
|
||||
'geo.point.coordinates': {
|
||||
@@ -486,34 +479,18 @@ describe('Query', function () {
|
||||
it('should build geo filter for shapes and points', function () {
|
||||
const filter = buildFilter(searchFilters.geoPoint);
|
||||
const expectedFilter = {
|
||||
bool: {
|
||||
minimum_should_match: 1,
|
||||
should: [
|
||||
{
|
||||
geo_shape: {
|
||||
'geo.polygon': {
|
||||
relation: undefined,
|
||||
shape: {
|
||||
type: 'envelope',
|
||||
coordinates: [
|
||||
[50.123, 8.123],
|
||||
[50.123, 8.123],
|
||||
],
|
||||
},
|
||||
},
|
||||
'ignore_unmapped': true,
|
||||
},
|
||||
geo_shape: {
|
||||
'geo.polygon': {
|
||||
relation: undefined,
|
||||
shape: {
|
||||
type: 'envelope',
|
||||
coordinates: [
|
||||
[50.123, 8.123],
|
||||
[50.123, 8.123],
|
||||
],
|
||||
},
|
||||
{
|
||||
geo_bounding_box: {
|
||||
'geo.point.coordinates': {
|
||||
bottom_right: [50.123, 8.123],
|
||||
top_left: [50.123, 8.123],
|
||||
},
|
||||
'ignore_unmapped': true,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
'ignore_unmapped': true,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -543,7 +520,7 @@ describe('Query', function () {
|
||||
|
||||
it('should build boolean filter', function () {
|
||||
const filter = buildFilter(searchFilters.boolean);
|
||||
const expectedFilter: ESBooleanFilter<any> = {
|
||||
const expectedFilter: QueryDslSpecificQueryContainer<'bool'> = {
|
||||
bool: {
|
||||
minimum_should_match: 0,
|
||||
must: [
|
||||
@@ -604,8 +581,8 @@ describe('Query', function () {
|
||||
},
|
||||
},
|
||||
];
|
||||
let sorts: Array<ESGenericSort | ESGeoDistanceSort | ScriptSort> = [];
|
||||
const expectedSorts: {[key: string]: ESGenericSort | ESGeoDistanceSort | ScriptSort} = {
|
||||
let sorts: SortCombinations[] = [];
|
||||
const expectedSorts: {[key: string]: SortCombinations} = {
|
||||
ducet: {
|
||||
'name.sort': 'desc',
|
||||
},
|
||||
@@ -632,7 +609,7 @@ describe('Query', function () {
|
||||
},
|
||||
};
|
||||
before(function () {
|
||||
sorts = buildSort(searchSCSearchSort);
|
||||
sorts = buildSort(searchSCSearchSort) as SortCombinations[];
|
||||
});
|
||||
|
||||
it('should build ducet sort', function () {
|
||||
@@ -649,10 +626,10 @@ describe('Query', function () {
|
||||
|
||||
it('should build price sort', function () {
|
||||
const priceSortNoScript = {
|
||||
...sorts[3],
|
||||
...(sorts[3] as any),
|
||||
_script: {
|
||||
...(sorts[3] as ScriptSort)._script,
|
||||
script: (expectedSorts.price as ScriptSort)._script.script,
|
||||
...(sorts[3] as any)._script,
|
||||
script: (expectedSorts.price as any)._script.script,
|
||||
},
|
||||
};
|
||||
expect(priceSortNoScript).to.be.eql(expectedSorts.price);
|
||||
|
||||
Reference in New Issue
Block a user