mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-10-21 00:41:44 +00:00
refactor: update elasticsearch to 8.19
This commit is contained in:
@@ -43,7 +43,7 @@
|
||||
"test:unit": "cross-env NODE_CONFIG_ENV=elasticsearch ALLOW_NO_TRANSPORT=true STAPPS_LOG_LEVEL=0 mocha --exit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@elastic/elasticsearch": "8.14.1",
|
||||
"@elastic/elasticsearch": "8.19.2",
|
||||
"@openstapps/core": "workspace:*",
|
||||
"@openstapps/core-tools": "workspace:*",
|
||||
"@openstapps/logger": "workspace:*",
|
||||
|
||||
@@ -13,12 +13,7 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {
|
||||
AggregateName,
|
||||
AggregationsAggregate,
|
||||
AggregationsFiltersAggregate,
|
||||
AggregationsMultiTermsBucket,
|
||||
} from '@elastic/elasticsearch/lib/api/types.js';
|
||||
import {estypes} from '@elastic/elasticsearch';
|
||||
import {SCFacet, SCThingType} from '@openstapps/core';
|
||||
|
||||
/**
|
||||
@@ -26,16 +21,16 @@ import {SCFacet, SCThingType} from '@openstapps/core';
|
||||
* @param aggregationResponse - aggregations response from elasticsearch
|
||||
*/
|
||||
export function parseAggregations(
|
||||
aggregationResponse: Record<AggregateName, AggregationsAggregate>,
|
||||
aggregationResponse: Record<estypes.AggregateName, estypes.AggregationsAggregate>,
|
||||
): SCFacet[] {
|
||||
const facets: SCFacet[] = [];
|
||||
|
||||
for (const aggregateName in aggregationResponse) {
|
||||
const aggregation = aggregationResponse[aggregateName] as AggregationsMultiTermsBucket;
|
||||
const aggregation = aggregationResponse[aggregateName] as estypes.AggregationsMultiTermsBucket;
|
||||
const type = aggregateName === '@all' ? {} : {onlyOnType: aggregateName as SCThingType};
|
||||
|
||||
for (const field in aggregation) {
|
||||
const fieldAggregate = aggregation[field] as AggregationsFiltersAggregate;
|
||||
const fieldAggregate = aggregation[field] as estypes.AggregationsFiltersAggregate;
|
||||
if (typeof fieldAggregate !== 'object') continue;
|
||||
|
||||
const buckets = Object.values(fieldAggregate.buckets).map(bucket => {
|
||||
|
||||
@@ -14,13 +14,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Client, events} from '@elastic/elasticsearch';
|
||||
import {
|
||||
AggregateName,
|
||||
AggregationsMultiTermsBucket,
|
||||
IndicesGetAliasResponse,
|
||||
SearchHit,
|
||||
SearchResponse,
|
||||
} from '@elastic/elasticsearch/lib/api/types.js';
|
||||
import {estypes} from '@elastic/elasticsearch';
|
||||
import {SCConfigFile, SCSearchQuery, SCSearchResponse, SCThings, SCUuid} from '@openstapps/core';
|
||||
import {Logger} from '@openstapps/logger';
|
||||
import moment from 'moment';
|
||||
@@ -113,7 +107,9 @@ export class Elasticsearch implements Database {
|
||||
/**
|
||||
* Gets a map which contains each alias and all indices that are associated with each alias
|
||||
*/
|
||||
private async cleanupDeadIndices(retryOptions: Partial<RetryOptions<IndicesGetAliasResponse>> = {}) {
|
||||
private async cleanupDeadIndices(
|
||||
retryOptions: Partial<RetryOptions<estypes.IndicesGetAliasResponse>> = {},
|
||||
) {
|
||||
const aliasResponse = await retryCatch({
|
||||
maxRetries: 10,
|
||||
retryInterval: 2000,
|
||||
@@ -147,7 +143,7 @@ export class Elasticsearch implements Database {
|
||||
* @param uid an UID to use for the search
|
||||
* @returns an elasticsearch object containing the thing
|
||||
*/
|
||||
private async getObject(uid: SCUuid): Promise<SearchHit<SCThings> | undefined> {
|
||||
private async getObject(uid: SCUuid): Promise<estypes.SearchHit<SCThings> | undefined> {
|
||||
const searchResponse = await this.client.search<SCThings>({
|
||||
body: {
|
||||
query: {
|
||||
@@ -273,7 +269,9 @@ export class Elasticsearch implements Database {
|
||||
/**
|
||||
* Initialize the elasticsearch database (call all needed methods)
|
||||
*/
|
||||
public async init(retryOptions: Partial<RetryOptions<IndicesGetAliasResponse>> = {}): Promise<void> {
|
||||
public async init(
|
||||
retryOptions: Partial<RetryOptions<estypes.IndicesGetAliasResponse>> = {},
|
||||
): Promise<void> {
|
||||
const monitoringConfiguration = this.config.internal.monitoring;
|
||||
|
||||
if (monitoringConfiguration !== undefined) {
|
||||
@@ -373,7 +371,7 @@ export class Elasticsearch implements Database {
|
||||
| undefined,
|
||||
};
|
||||
|
||||
const response: SearchResponse<SCThings> = await this.client.search({
|
||||
const response: estypes.SearchResponse<SCThings> = await this.client.search({
|
||||
aggs: aggregations,
|
||||
query: buildQuery(parameters, this.config, esConfig),
|
||||
from: parameters.from,
|
||||
@@ -394,7 +392,9 @@ export class Elasticsearch implements Database {
|
||||
facets:
|
||||
response.aggregations === undefined
|
||||
? []
|
||||
: parseAggregations(response.aggregations as Record<AggregateName, AggregationsMultiTermsBucket>),
|
||||
: parseAggregations(
|
||||
response.aggregations as Record<estypes.AggregateName, estypes.AggregationsMultiTermsBucket>,
|
||||
),
|
||||
pagination: {
|
||||
count: response.hits.hits.length,
|
||||
offset: typeof parameters.from === 'number' ? parameters.from : 0,
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Client} from '@elastic/elasticsearch';
|
||||
import {SearchRequest} from '@elastic/elasticsearch/lib/api/types.js';
|
||||
import {estypes} from '@elastic/elasticsearch';
|
||||
import {
|
||||
SCMonitoringConfiguration,
|
||||
SCMonitoringLogAction,
|
||||
@@ -128,7 +128,7 @@ export async function setUp(
|
||||
|
||||
cron.schedule(trigger.executionTime, async () => {
|
||||
// execute watch (search->condition->action)
|
||||
const result = await esClient.search<SCThings>(watcher.query as SearchRequest);
|
||||
const result = await esClient.search<SCThings>(watcher.query as estypes.SearchRequest);
|
||||
|
||||
// check conditions
|
||||
const total =
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {QueryDslFunctionScoreContainer} from '@elastic/elasticsearch/lib/api/types.js';
|
||||
import {estypes} from '@elastic/elasticsearch';
|
||||
import {SCBackendConfigurationSearchBoostingType} from '@openstapps/core';
|
||||
import {QueryDslSpecificQueryContainer} from '../../types/util.js';
|
||||
|
||||
@@ -22,8 +22,8 @@ import {QueryDslSpecificQueryContainer} from '../../types/util.js';
|
||||
*/
|
||||
export function buildFunctionsForBoostingTypes(
|
||||
boostingTypes: SCBackendConfigurationSearchBoostingType[],
|
||||
): QueryDslFunctionScoreContainer[] {
|
||||
const functions: QueryDslFunctionScoreContainer[] = [];
|
||||
): estypes.QueryDslFunctionScoreContainer[] {
|
||||
const functions: estypes.QueryDslFunctionScoreContainer[] = [];
|
||||
|
||||
for (const boostingForOneSCType of boostingTypes) {
|
||||
const typeFilter: QueryDslSpecificQueryContainer<'term'> = {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {QueryDslFunctionScoreContainer} from '@elastic/elasticsearch/lib/api/types.js';
|
||||
import {estypes} from '@elastic/elasticsearch';
|
||||
import {SCBackendConfigurationSearchBoostingContext, SCSearchContext} from '@openstapps/core';
|
||||
import {buildFunctionsForBoostingTypes} from './boost-functions.js';
|
||||
|
||||
@@ -24,7 +24,7 @@ import {buildFunctionsForBoostingTypes} from './boost-functions.js';
|
||||
export function buildScoringFunctions(
|
||||
boostings: SCBackendConfigurationSearchBoostingContext,
|
||||
context: SCSearchContext | undefined,
|
||||
): QueryDslFunctionScoreContainer[] {
|
||||
): estypes.QueryDslFunctionScoreContainer[] {
|
||||
// default context
|
||||
let functions = buildFunctionsForBoostingTypes(boostings['default' as SCSearchContext]);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {QueryDslQueryContainer} from '@elastic/elasticsearch/lib/api/types.js';
|
||||
import {estypes} from '@elastic/elasticsearch';
|
||||
import {SCSearchFilter} from '@openstapps/core';
|
||||
import {buildBooleanFilter} from './filters/boolean.js';
|
||||
import {buildAvailabilityFilter} from './filters/availability.js';
|
||||
@@ -26,7 +26,7 @@ import {buildValueFilter} from './filters/value.js';
|
||||
* Converts Array of Filters to elasticsearch query-syntax
|
||||
* @param filter A search filter for the retrieval of the data
|
||||
*/
|
||||
export function buildFilter(filter: SCSearchFilter): QueryDslQueryContainer {
|
||||
export function buildFilter(filter: SCSearchFilter): estypes.QueryDslQueryContainer {
|
||||
switch (filter.type) {
|
||||
case 'value': {
|
||||
return buildValueFilter(filter);
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {QueryDslBoolQuery} from '@elastic/elasticsearch/lib/api/types.js';
|
||||
import {estypes} from '@elastic/elasticsearch';
|
||||
import {SCSearchBooleanFilter} from '@openstapps/core';
|
||||
import {QueryDslSpecificQueryContainer} from '../../types/util.js';
|
||||
import {buildFilter} from '../filter.js';
|
||||
@@ -22,7 +22,7 @@ import {buildFilter} from '../filter.js';
|
||||
* @param filter A search filter for the retrieval of the data
|
||||
*/
|
||||
export function buildBooleanFilter(filter: SCSearchBooleanFilter): QueryDslSpecificQueryContainer<'bool'> {
|
||||
const result: QueryDslBoolQuery = {
|
||||
const result: estypes.QueryDslBoolQuery = {
|
||||
minimum_should_match: 0,
|
||||
must: [],
|
||||
must_not: [],
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {QueryDslDateRangeQuery} from '@elastic/elasticsearch/lib/api/types.js';
|
||||
import {estypes} from '@elastic/elasticsearch';
|
||||
import {SCSearchDateRangeFilter} from '@openstapps/core';
|
||||
import {QueryDslSpecificQueryContainer} from '../../types/util.js';
|
||||
|
||||
@@ -23,7 +23,7 @@ import {QueryDslSpecificQueryContainer} from '../../types/util.js';
|
||||
export function buildDateRangeFilter(
|
||||
filter: SCSearchDateRangeFilter,
|
||||
): QueryDslSpecificQueryContainer<'range'> {
|
||||
const dateRangeObject: QueryDslDateRangeQuery = {
|
||||
const dateRangeObject: estypes.QueryDslDateRangeQuery = {
|
||||
format: filter.arguments.format,
|
||||
time_zone: filter.arguments.timeZone,
|
||||
relation: filter.arguments.relation,
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {QueryDslGeoDistanceQuery} from '@elastic/elasticsearch/lib/api/types.js';
|
||||
import {estypes} from '@elastic/elasticsearch';
|
||||
import {SCSearchDistanceFilter} from '@openstapps/core';
|
||||
import {QueryDslSpecificQueryContainer} from '../../types/util.js';
|
||||
|
||||
@@ -23,7 +23,7 @@ import {QueryDslSpecificQueryContainer} from '../../types/util.js';
|
||||
export function buildDistanceFilter(
|
||||
filter: SCSearchDistanceFilter,
|
||||
): QueryDslSpecificQueryContainer<'geo_distance'> {
|
||||
const geoObject: QueryDslGeoDistanceQuery = {
|
||||
const geoObject: estypes.QueryDslGeoDistanceQuery = {
|
||||
distance: `${filter.arguments.distance}m`,
|
||||
[`${filter.arguments.field}.point`]: {
|
||||
lat: filter.arguments.position[1],
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {QueryDslNumberRangeQuery} from '@elastic/elasticsearch/lib/api/types.js';
|
||||
import {estypes} from '@elastic/elasticsearch';
|
||||
import {SCSearchNumericRangeFilter} from '@openstapps/core';
|
||||
import {QueryDslSpecificQueryContainer} from '../../types/util.js';
|
||||
|
||||
@@ -23,7 +23,7 @@ import {QueryDslSpecificQueryContainer} from '../../types/util.js';
|
||||
export function buildNumericRangeFilter(
|
||||
filter: SCSearchNumericRangeFilter,
|
||||
): QueryDslSpecificQueryContainer<'range'> {
|
||||
const numericRangeObject: QueryDslNumberRangeQuery = {
|
||||
const numericRangeObject: estypes.QueryDslNumberRangeQuery = {
|
||||
relation: filter.arguments.relation,
|
||||
};
|
||||
if (filter.arguments.bounds.lowerBound?.mode === 'exclusive') {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {QueryDslQueryContainer} from '@elastic/elasticsearch/lib/api/types.js';
|
||||
import {estypes} from '@elastic/elasticsearch';
|
||||
import {SCConfigFile, SCSearchQuery} from '@openstapps/core';
|
||||
import {ElasticsearchConfig} from '../types/elasticsearch-config.js';
|
||||
import {buildFilter} from './filter.js';
|
||||
@@ -29,7 +29,7 @@ export const buildQuery = function buildQuery(
|
||||
parameters: SCSearchQuery,
|
||||
defaultConfig: SCConfigFile,
|
||||
elasticsearchConfig: ElasticsearchConfig,
|
||||
): QueryDslQueryContainer {
|
||||
): estypes.QueryDslQueryContainer {
|
||||
// if config provides a minMatch parameter, we use query_string instead of a match query
|
||||
let query;
|
||||
if (elasticsearchConfig.query === undefined) {
|
||||
@@ -83,7 +83,7 @@ export const buildQuery = function buildQuery(
|
||||
);
|
||||
}
|
||||
|
||||
const functionScoreQuery: QueryDslQueryContainer = {
|
||||
const functionScoreQuery: estypes.QueryDslQueryContainer = {
|
||||
function_score: {
|
||||
functions: buildScoringFunctions(defaultConfig.internal.boostings, parameters.context),
|
||||
query: {
|
||||
@@ -97,7 +97,8 @@ export const buildQuery = function buildQuery(
|
||||
},
|
||||
};
|
||||
|
||||
const mustMatch = functionScoreQuery.function_score?.query?.bool?.must;
|
||||
const mustMatch = (functionScoreQuery.function_score as estypes.QueryDslFunctionScoreQuery | undefined)
|
||||
?.query?.bool?.must;
|
||||
|
||||
if (Array.isArray(mustMatch)) {
|
||||
if (query !== undefined) {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Sort} from '@elastic/elasticsearch/lib/api/types.js';
|
||||
import {estypes} from '@elastic/elasticsearch';
|
||||
import {SCSearchSort} from '@openstapps/core';
|
||||
import {buildDistanceSort} from './sort/distance.js';
|
||||
import {buildDucetSort} from './sort/ducet.js';
|
||||
@@ -24,7 +24,7 @@ import {buildPriceSort} from './sort/price.js';
|
||||
* @param sorts Sorting rules to apply to the data that is being queried
|
||||
* @returns an array of sort queries
|
||||
*/
|
||||
export const buildSort = function buildSort(sorts: SCSearchSort[]): Sort {
|
||||
export const buildSort = function buildSort(sorts: SCSearchSort[]): estypes.Sort {
|
||||
return sorts.map(sort => {
|
||||
switch (sort.type) {
|
||||
case 'generic': {
|
||||
|
||||
@@ -12,14 +12,14 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {SortOptions} from '@elastic/elasticsearch/lib/api/types.js';
|
||||
import {estypes} from '@elastic/elasticsearch';
|
||||
import {SCDistanceSort} from '@openstapps/core';
|
||||
|
||||
/**
|
||||
* Converts a distance sort to elasticsearch syntax
|
||||
* @param sort A sorting definition
|
||||
*/
|
||||
export function buildDistanceSort(sort: SCDistanceSort): SortOptions {
|
||||
export function buildDistanceSort(sort: SCDistanceSort): estypes.SortOptions {
|
||||
return {
|
||||
_geo_distance: {
|
||||
mode: 'avg',
|
||||
|
||||
@@ -12,14 +12,14 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {SortOptions} from '@elastic/elasticsearch/lib/api/types.js';
|
||||
import {estypes} from '@elastic/elasticsearch';
|
||||
import {SCDucetSort} from '@openstapps/core';
|
||||
|
||||
/**
|
||||
* Converts a ducet sort to elasticsearch syntax
|
||||
* @param sort A sorting definition
|
||||
*/
|
||||
export function buildDucetSort(sort: SCDucetSort): SortOptions {
|
||||
export function buildDucetSort(sort: SCDucetSort): estypes.SortOptions {
|
||||
return {
|
||||
[`${sort.arguments.field}.sort`]: sort.order,
|
||||
};
|
||||
|
||||
@@ -12,14 +12,14 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {SortOptions} from '@elastic/elasticsearch/lib/api/types.js';
|
||||
import {estypes} from '@elastic/elasticsearch';
|
||||
import {SCGenericSort} from '@openstapps/core';
|
||||
|
||||
/**
|
||||
* Converts a generic sort to elasticsearch syntax
|
||||
* @param sort A sorting definition
|
||||
*/
|
||||
export function buildGenericSort(sort: SCGenericSort): SortOptions {
|
||||
export function buildGenericSort(sort: SCGenericSort): estypes.SortOptions {
|
||||
return {
|
||||
[sort.arguments.field]: sort.order,
|
||||
};
|
||||
|
||||
@@ -12,14 +12,14 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {SortOptions} from '@elastic/elasticsearch/lib/api/types.js';
|
||||
import {estypes} from '@elastic/elasticsearch';
|
||||
import {SCPriceSort, SCSportCoursePriceGroup, SCThingsField} from '@openstapps/core';
|
||||
|
||||
/**
|
||||
* Converts a price sort to elasticsearch syntax
|
||||
* @param sort A sorting definition
|
||||
*/
|
||||
export function buildPriceSort(sort: SCPriceSort): SortOptions {
|
||||
export function buildPriceSort(sort: SCPriceSort): estypes.SortOptions {
|
||||
return {
|
||||
_script: {
|
||||
order: sort.order,
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Client} from '@elastic/elasticsearch';
|
||||
import {Client, estypes} from '@elastic/elasticsearch';
|
||||
import {SCThingType} from '@openstapps/core';
|
||||
import type {AggregationSchema} from '@openstapps/core/lib/mappings/aggregations.json.js';
|
||||
import type {ElasticsearchTemplateCollection} from '@openstapps/core/lib/mappings/mappings.json.js';
|
||||
@@ -36,7 +36,10 @@ export const aggregations = JSON.parse(
|
||||
* @param client An elasticsearch client to use
|
||||
* @param type the SCThingType of which the template should be set
|
||||
*/
|
||||
export async function putTemplate(client: Client, type: SCThingType) {
|
||||
export async function putTemplate(
|
||||
client: Client,
|
||||
type: SCThingType,
|
||||
): Promise<estypes.IndicesPutTemplateResponse> {
|
||||
const sanitizedType = `template_${type.replaceAll(/\s/g, '_')}`;
|
||||
|
||||
return client.indices.putTemplate({
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {QueryDslQueryContainer} from '@elastic/elasticsearch/lib/api/types.js';
|
||||
import {estypes} from '@elastic/elasticsearch';
|
||||
|
||||
export type QueryDslSpecificQueryContainer<T extends keyof QueryDslQueryContainer> = Required<
|
||||
Pick<QueryDslQueryContainer, T>
|
||||
export type QueryDslSpecificQueryContainer<T extends keyof estypes.QueryDslQueryContainer> = Required<
|
||||
Pick<estypes.QueryDslQueryContainer, T>
|
||||
>;
|
||||
|
||||
@@ -13,13 +13,13 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {AggregateName, AggregationsMultiTermsBucket} from '@elastic/elasticsearch/lib/api/types.js';
|
||||
import {estypes} from '@elastic/elasticsearch';
|
||||
import {SCFacet, SCThingType} from '@openstapps/core';
|
||||
import {expect} from 'chai';
|
||||
import {parseAggregations} from '../../../src/storage/elasticsearch/aggregations.js';
|
||||
|
||||
describe('Aggregations', function () {
|
||||
const aggregations: Record<AggregateName, Partial<AggregationsMultiTermsBucket>> = {
|
||||
const aggregations: Record<estypes.AggregateName, Partial<estypes.AggregationsMultiTermsBucket>> = {
|
||||
'catalog': {
|
||||
'doc_count': 4,
|
||||
'superCatalogs.categories': {
|
||||
|
||||
@@ -14,9 +14,7 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Client, Diagnostic} from '@elastic/elasticsearch';
|
||||
import Indices from '@elastic/elasticsearch/lib/api/api/indices.js';
|
||||
import {CreateResponse, SearchHit, SearchResponse} from '@elastic/elasticsearch/lib/api/types.js';
|
||||
import {Client, Diagnostic, estypes} from '@elastic/elasticsearch';
|
||||
import {
|
||||
SCBook,
|
||||
SCBulkResponse,
|
||||
@@ -52,6 +50,7 @@ import {query} from './query.js';
|
||||
import messageFile from '@openstapps/core/test/resources/indexable/Message.1.json' with {type: 'json'};
|
||||
import bookFile from '@openstapps/core/test/resources/indexable/Book.1.json' with {type: 'json'};
|
||||
|
||||
const indicesPrototype = Object.getPrototypeOf(new Client({node: 'http://localhost:9200'}).indices);
|
||||
const message = messageFile.instance as SCMessage;
|
||||
const book = bookFile.instance as SCBook;
|
||||
|
||||
@@ -60,7 +59,7 @@ use(chaiAsPromised);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function searchResponse<T>(...hits: SearchHit<T>[]): SearchResponse<T> {
|
||||
function searchResponse<T>(...hits: estypes.SearchHit<T>[]): estypes.SearchResponse<T> {
|
||||
return {hits: {hits}, took: 0, timed_out: false, _shards: {total: 1, failed: 0, successful: 1}};
|
||||
}
|
||||
|
||||
@@ -312,13 +311,13 @@ describe('Elasticsearch', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
sandbox
|
||||
.stub(Indices.default.prototype, 'getAlias')
|
||||
.stub(indicesPrototype, 'getAlias')
|
||||
.resolves({[oldIndex]: {aliases: {[SCThingType.Book]: {}}}} as any);
|
||||
sandbox.stub(Indices.default.prototype, 'putTemplate').resolves({} as any);
|
||||
createStub = sandbox.stub(Indices.default.prototype, 'create').resolves({} as any);
|
||||
deleteStub = sandbox.stub(Indices.default.prototype, 'delete').resolves({} as any);
|
||||
refreshStub = sandbox.stub(Indices.default.prototype, 'refresh').resolves({} as any);
|
||||
updateAliasesStub = sandbox.stub(Indices.default.prototype, 'updateAliases').resolves({} as any);
|
||||
sandbox.stub(indicesPrototype, 'putTemplate').resolves({} as any);
|
||||
createStub = sandbox.stub(indicesPrototype, 'create').resolves({} as any);
|
||||
deleteStub = sandbox.stub(indicesPrototype, 'delete').resolves({} as any);
|
||||
refreshStub = sandbox.stub(indicesPrototype, 'refresh').resolves({} as any);
|
||||
updateAliasesStub = sandbox.stub(indicesPrototype, 'updateAliases').resolves({} as any);
|
||||
es = new Elasticsearch(backendConfig);
|
||||
});
|
||||
|
||||
@@ -445,7 +444,7 @@ describe('Elasticsearch', function () {
|
||||
});
|
||||
|
||||
it('should provide the thing if object is found', async function () {
|
||||
const foundObject: SearchHit<SCMessage> = {
|
||||
const foundObject: estypes.SearchHit<SCMessage> = {
|
||||
_id: '',
|
||||
_index: '',
|
||||
_score: 0,
|
||||
@@ -466,7 +465,7 @@ describe('Elasticsearch', function () {
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
sandbox.stub(Indices.default.prototype, 'getAlias').resolves({} as any);
|
||||
sandbox.stub(indicesPrototype, 'getAlias').resolves({} as any);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
@@ -476,7 +475,7 @@ describe('Elasticsearch', function () {
|
||||
it('should not post if the object already exists in an index which will not be rolled over', async function () {
|
||||
const index = getIndex();
|
||||
const oldIndex = index.replace('foosource', 'barsource');
|
||||
const object: SearchHit<SCMessage> = {
|
||||
const object: estypes.SearchHit<SCMessage> = {
|
||||
_id: '',
|
||||
_index: oldIndex,
|
||||
_source: message,
|
||||
@@ -490,7 +489,7 @@ describe('Elasticsearch', function () {
|
||||
|
||||
it('should reject if there is an object creation error on the elasticsearch side', async function () {
|
||||
sandbox.stub(es.client, 'search').resolves(searchResponse());
|
||||
sandbox.stub(es.client, 'create').resolves({result: 'not_found'} as CreateResponse);
|
||||
sandbox.stub(es.client, 'create').resolves({result: 'not_found'} as estypes.CreateResponse);
|
||||
|
||||
await es.init();
|
||||
return expect(es.post(message, bulk)).to.rejectedWith('creation');
|
||||
@@ -527,7 +526,7 @@ describe('Elasticsearch', function () {
|
||||
sandbox.restore();
|
||||
});
|
||||
it('should reject to put if the object does not already exist', async function () {
|
||||
const object: SearchHit<SCMessage> = {
|
||||
const object: estypes.SearchHit<SCMessage> = {
|
||||
_id: '',
|
||||
_index: getIndex(),
|
||||
_score: 0,
|
||||
@@ -541,7 +540,7 @@ describe('Elasticsearch', function () {
|
||||
// noinspection JSUnusedLocalSymbols
|
||||
it('should update the object if it already exists', async function () {
|
||||
let caughtParameter: any;
|
||||
const object: SearchHit<SCMessage> = {
|
||||
const object: estypes.SearchHit<SCMessage> = {
|
||||
_id: '',
|
||||
_index: getIndex(),
|
||||
_score: 0,
|
||||
@@ -564,13 +563,13 @@ describe('Elasticsearch', function () {
|
||||
describe('search', async function () {
|
||||
let es: Elasticsearch;
|
||||
const sandbox = sinon.createSandbox();
|
||||
const objectMessage: SearchHit<SCMessage> = {
|
||||
const objectMessage: estypes.SearchHit<SCMessage> = {
|
||||
_id: '123',
|
||||
_index: getIndex(),
|
||||
_score: 0,
|
||||
_source: message,
|
||||
};
|
||||
const objectBook: SearchHit<SCBook> = {
|
||||
const objectBook: estypes.SearchHit<SCBook> = {
|
||||
_id: '321',
|
||||
_index: getIndex(),
|
||||
_score: 0,
|
||||
@@ -595,7 +594,7 @@ describe('Elasticsearch', function () {
|
||||
},
|
||||
},
|
||||
};
|
||||
const fakeSearchResponse: SearchResponse<SCThings> = {
|
||||
const fakeSearchResponse: estypes.SearchResponse<SCThings> = {
|
||||
took: 12,
|
||||
timed_out: false,
|
||||
// @ts-expect-error not assignable
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Client} from '@elastic/elasticsearch';
|
||||
import {SearchResponse} from '@elastic/elasticsearch/lib/api/types.js';
|
||||
import {estypes} from '@elastic/elasticsearch';
|
||||
import {
|
||||
SCMonitoringConfiguration,
|
||||
SCMonitoringLogAction,
|
||||
@@ -111,7 +111,7 @@ describe('Monitoring', async function () {
|
||||
});
|
||||
|
||||
it('should log errors where conditions failed', async function () {
|
||||
const fakeSearchResponse: SearchResponse<SCThings> = {
|
||||
const fakeSearchResponse: estypes.SearchResponse<SCThings> = {
|
||||
took: 12,
|
||||
timed_out: false,
|
||||
// @ts-expect-error not assignable
|
||||
|
||||
@@ -31,7 +31,7 @@ import {buildQuery} from '../../../src/storage/elasticsearch/query/query.js';
|
||||
import {buildSort} from '../../../src/storage/elasticsearch/query/sort.js';
|
||||
import {ElasticsearchConfig} from '../../../src/storage/elasticsearch/types/elasticsearch-config.js';
|
||||
import {QueryDslSpecificQueryContainer} from '../../../src/storage/elasticsearch/types/util.js';
|
||||
import {QueryDslRangeQuery, SortCombinations} from '@elastic/elasticsearch/lib/api/types.js';
|
||||
import {estypes} from '@elastic/elasticsearch';
|
||||
import {backendConfig} from '../../../src/config.js';
|
||||
|
||||
describe('Query', function () {
|
||||
@@ -364,9 +364,9 @@ describe('Query', function () {
|
||||
expect(filter).to.deep.equal(expectedFilter);
|
||||
for (const bound of ['g', 'l']) {
|
||||
const inclusiveExists =
|
||||
typeof filter.range.price?.[`${bound}t` as keyof QueryDslRangeQuery] !== 'undefined';
|
||||
typeof filter.range.price?.[`${bound}t` as keyof estypes.QueryDslRangeQuery] !== 'undefined';
|
||||
const exclusiveExists =
|
||||
typeof filter.range.price?.[`${bound}te` as keyof QueryDslRangeQuery] !== 'undefined';
|
||||
typeof filter.range.price?.[`${bound}te` as keyof estypes.QueryDslRangeQuery] !== 'undefined';
|
||||
|
||||
// only one should exist at the same time
|
||||
expect(inclusiveExists && exclusiveExists).to.be.false;
|
||||
@@ -623,8 +623,8 @@ describe('Query', function () {
|
||||
},
|
||||
},
|
||||
];
|
||||
let sorts: SortCombinations[] = [];
|
||||
const expectedSorts: {[key: string]: SortCombinations} = {
|
||||
let sorts: estypes.SortCombinations[] = [];
|
||||
const expectedSorts: {[key: string]: estypes.SortCombinations} = {
|
||||
ducet: {
|
||||
'name.sort': 'desc',
|
||||
},
|
||||
@@ -651,7 +651,7 @@ describe('Query', function () {
|
||||
},
|
||||
};
|
||||
before(function () {
|
||||
sorts = buildSort(searchSCSearchSort) as SortCombinations[];
|
||||
sorts = buildSort(searchSCSearchSort) as estypes.SortCombinations[];
|
||||
});
|
||||
|
||||
it('should build ducet sort', function () {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {QueryDslQueryContainer} from '@elastic/elasticsearch/lib/api/types.js';
|
||||
import {estypes} from '@elastic/elasticsearch';
|
||||
|
||||
export const query: QueryDslQueryContainer = {
|
||||
export const query: estypes.QueryDslQueryContainer = {
|
||||
function_score: {
|
||||
functions: [
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM elasticsearch:8.14.3
|
||||
FROM elasticsearch:8.19.21
|
||||
|
||||
EXPOSE 9200
|
||||
EXPOSE 9300
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
"test": "c8 mocha"
|
||||
},
|
||||
"dependencies": {
|
||||
"@elastic/elasticsearch": "8.14.1",
|
||||
"@elastic/elasticsearch": "8.19.2",
|
||||
"commander": "10.0.0",
|
||||
"deepmerge": "4.3.1",
|
||||
"flatted": "3.2.7",
|
||||
|
||||
Generated
+62
-10
@@ -61,8 +61,8 @@ importers:
|
||||
backend/backend:
|
||||
dependencies:
|
||||
'@elastic/elasticsearch':
|
||||
specifier: 8.14.1
|
||||
version: 8.14.1
|
||||
specifier: 8.19.2
|
||||
version: 8.19.2
|
||||
'@openstapps/core':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/core
|
||||
@@ -1215,7 +1215,7 @@ importers:
|
||||
version: 0.6.7
|
||||
ts-node:
|
||||
specifier: 10.9.2
|
||||
version: 10.9.2(@types/node@22.15.31)(typescript@5.9.3)
|
||||
version: 10.9.2(@types/node@25.9.9)(typescript@5.9.3)
|
||||
tsup:
|
||||
specifier: 8.5.0
|
||||
version: 8.5.0(jiti@1.21.7)(postcss@8.5.26)(typescript@5.9.3)
|
||||
@@ -1466,7 +1466,7 @@ importers:
|
||||
version: 3.1.1
|
||||
ts-node:
|
||||
specifier: 10.9.2
|
||||
version: 10.9.2(@types/node@22.15.31)(typescript@5.9.3)
|
||||
version: 10.9.2(@types/node@25.9.9)(typescript@5.9.3)
|
||||
tsup:
|
||||
specifier: 8.5.0
|
||||
version: 8.5.0(jiti@1.21.7)(postcss@8.5.26)(typescript@5.9.3)
|
||||
@@ -1885,8 +1885,8 @@ importers:
|
||||
packages/es-mapping-generator:
|
||||
dependencies:
|
||||
'@elastic/elasticsearch':
|
||||
specifier: 8.14.1
|
||||
version: 8.14.1
|
||||
specifier: 8.19.2
|
||||
version: 8.19.2
|
||||
commander:
|
||||
specifier: 10.0.0
|
||||
version: 10.0.0
|
||||
@@ -3400,9 +3400,9 @@ packages:
|
||||
resolution: {integrity: sha512-XQsZgjm2EcVUiZQf11UBJQfmZeEmOW8DpI1gsFeln6w0ae0ii4dMQEQ0kjl6DspdWX1aGY1/loyXnP0JS06e/A==}
|
||||
engines: {node: '>=0.8.0'}
|
||||
|
||||
'@elastic/elasticsearch@8.14.1':
|
||||
resolution: {integrity: sha512-gRFtAt9ALUVhR7ngAh7MROMejE16viNHy6hluZc/mMO6IRFRqeFqa/NOqmvP5wK+2z8N8a73ebpMDOCuNrYUCQ==}
|
||||
engines: {node: '>=18'}
|
||||
'@elastic/elasticsearch@8.19.2':
|
||||
resolution: {integrity: sha512-LMJCju/+AZkDlJArd/MYABWTDrHi4U7j3qGTKi1hYC7+67SaiYmYFItiueACQVrj2j3ECPMcguZ+7WrZeB+Z5g==}
|
||||
engines: {node: '>=20'}
|
||||
|
||||
'@elastic/transport@8.10.0':
|
||||
resolution: {integrity: sha512-Xd62ZtgdrJuaunTLk0LqYtkUtJ3D2/NQ4QyLWPYj0c2h97SNUaNkrQH9lzb6r2P0Bdjx/HwKtW3X8kO5LJ7qEQ==}
|
||||
@@ -5323,6 +5323,9 @@ packages:
|
||||
'@types/node@22.15.31':
|
||||
resolution: {integrity: sha512-jnVe5ULKl6tijxUhvQeNbQG/84fHfg+yMak02cT8QVhBx/F05rAVxCGBYYTh2EKz22D6JF5ktXuNwdx7b9iEGw==}
|
||||
|
||||
'@types/node@25.9.9':
|
||||
resolution: {integrity: sha512-b4e2xxj/yMeT2hNlD6x7zNFiQK2Dlmkb9CQ6v3/1G2RezKN4YS2lcEv8lzGm1mhs4f2lM4yNAMI/zUDBZBBt7w==}
|
||||
|
||||
'@types/nodemailer@8.0.2':
|
||||
resolution: {integrity: sha512-c7M5ox8p0nEOfbJ2E9Qcmt8/QCu/VzsiAhzBiZbvky2PhKZDHpKB3sQHBM5MEZNkCfBOaS6S9//AGPRTNB7IaA==}
|
||||
|
||||
@@ -5737,6 +5740,10 @@ packages:
|
||||
resolution: {integrity: sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==}
|
||||
engines: {node: '>= 8'}
|
||||
|
||||
apache-arrow@21.2.0:
|
||||
resolution: {integrity: sha512-Hxe6Agq26gQOM954qpzYSllJBPJl+e16U5CkfuMUhLrNba+5nKkttIVlflaovN6oaTratqMGAO8H5u/aNhmHWQ==}
|
||||
hasBin: true
|
||||
|
||||
apache-crypt@1.2.6:
|
||||
resolution: {integrity: sha512-072WetlM4blL8PREJVeY+WHiUh1R5VNt2HfceGS8aKqttPHcmqE5pkKuXPz/ULmJOFkc8Hw3kfKl6vy7Qka6DA==}
|
||||
engines: {node: '>=8'}
|
||||
@@ -7743,6 +7750,9 @@ packages:
|
||||
resolution: {integrity: sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==}
|
||||
hasBin: true
|
||||
|
||||
flatbuffers@25.9.23:
|
||||
resolution: {integrity: sha512-MI1qs7Lo4Syw0EOzUl0xjs2lsoeqFku44KpngfIduHBYvzm8h2+7K8YMQh1JtVVVrUvhLpNwqVi4DERegUJhPQ==}
|
||||
|
||||
flatted@3.2.7:
|
||||
resolution: {integrity: sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==}
|
||||
|
||||
@@ -8845,6 +8855,9 @@ packages:
|
||||
json-stringify-safe@5.0.1:
|
||||
resolution: {integrity: sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==}
|
||||
|
||||
json-with-bigint@3.5.12:
|
||||
resolution: {integrity: sha512-uwbF/wSSuOgC7qqlq27Xp5B6a2MHVug3t0idZdTqu0JnlFvgJuH7ju+KAk/J06C7GfhoYy2gnb9wz2INqcne7w==}
|
||||
|
||||
json5@2.2.3:
|
||||
resolution: {integrity: sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==}
|
||||
engines: {node: '>=6'}
|
||||
@@ -12046,6 +12059,9 @@ packages:
|
||||
undici-types@6.21.0:
|
||||
resolution: {integrity: sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==}
|
||||
|
||||
undici-types@7.24.6:
|
||||
resolution: {integrity: sha512-WRNW+sJgj5OBN4/0JpHFqtqzhpbnV0GuB+OozA9gCL7a993SmU+1JBZCzLNxYsbMfIeDL+lTsphD5jN5N+n0zg==}
|
||||
|
||||
undici@6.21.3:
|
||||
resolution: {integrity: sha512-gBLkYIlEnSp8pFbT64yFgGE6UIB9tAkhukC23PmMDCe5Nd+cRqKxSjw5y54MK2AZMgZfJWMaNE4nYUHgi1XEOw==}
|
||||
engines: {node: '>=18.17'}
|
||||
@@ -15042,9 +15058,10 @@ snapshots:
|
||||
dependencies:
|
||||
'@types/hammerjs': 2.0.46
|
||||
|
||||
'@elastic/elasticsearch@8.14.1':
|
||||
'@elastic/elasticsearch@8.19.2':
|
||||
dependencies:
|
||||
'@elastic/transport': 8.10.0
|
||||
apache-arrow: 21.2.0
|
||||
tslib: 2.6.2
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
@@ -16945,6 +16962,10 @@ snapshots:
|
||||
dependencies:
|
||||
undici-types: 6.21.0
|
||||
|
||||
'@types/node@25.9.9':
|
||||
dependencies:
|
||||
undici-types: 7.24.6
|
||||
|
||||
'@types/nodemailer@8.0.2':
|
||||
dependencies:
|
||||
'@types/node': 22.15.31
|
||||
@@ -17502,6 +17523,13 @@ snapshots:
|
||||
normalize-path: 3.0.0
|
||||
picomatch: 2.3.1
|
||||
|
||||
apache-arrow@21.2.0:
|
||||
dependencies:
|
||||
'@types/node': 25.9.9
|
||||
flatbuffers: 25.9.23
|
||||
json-with-bigint: 3.5.12
|
||||
tslib: 2.6.2
|
||||
|
||||
apache-crypt@1.2.6:
|
||||
dependencies:
|
||||
unix-crypt-td-js: 1.1.4
|
||||
@@ -19958,6 +19986,8 @@ snapshots:
|
||||
|
||||
flat@5.0.2: {}
|
||||
|
||||
flatbuffers@25.9.23: {}
|
||||
|
||||
flatted@3.2.7: {}
|
||||
|
||||
flatted@3.4.1: {}
|
||||
@@ -21065,6 +21095,8 @@ snapshots:
|
||||
|
||||
json-stringify-safe@5.0.1: {}
|
||||
|
||||
json-with-bigint@3.5.12: {}
|
||||
|
||||
json5@2.2.3: {}
|
||||
|
||||
jsonc-parser@3.3.1: {}
|
||||
@@ -24752,6 +24784,24 @@ snapshots:
|
||||
v8-compile-cache-lib: 3.0.1
|
||||
yn: 3.1.1
|
||||
|
||||
ts-node@10.9.2(@types/node@25.9.9)(typescript@5.9.3):
|
||||
dependencies:
|
||||
'@cspotcode/source-map-support': 0.8.1
|
||||
'@tsconfig/node10': 1.0.12
|
||||
'@tsconfig/node12': 1.0.11
|
||||
'@tsconfig/node14': 1.0.3
|
||||
'@tsconfig/node16': 1.0.4
|
||||
'@types/node': 25.9.9
|
||||
acorn: 8.16.0
|
||||
acorn-walk: 8.3.5
|
||||
arg: 4.1.3
|
||||
create-require: 1.1.1
|
||||
diff: 4.0.4
|
||||
make-error: 1.3.6
|
||||
typescript: 5.9.3
|
||||
v8-compile-cache-lib: 3.0.1
|
||||
yn: 3.1.1
|
||||
|
||||
ts-toolbelt@9.6.0: {}
|
||||
|
||||
tslib@1.14.1: {}
|
||||
@@ -24967,6 +25017,8 @@ snapshots:
|
||||
|
||||
undici-types@6.21.0: {}
|
||||
|
||||
undici-types@7.24.6: {}
|
||||
|
||||
undici@6.21.3: {}
|
||||
|
||||
undici@6.28.1: {}
|
||||
|
||||
Reference in New Issue
Block a user