import { ElasticsearchQueryBuilderOperatorPlugin } from "~/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin" ; import { ElasticsearchBoolQueryConfig , ElasticsearchQueryBuilderArgsPlugin } from "~/types" ; export class ElasticsearchQueryBuilderOperatorAndInPlugin extends ElasticsearchQueryBuilderOperatorPlugin { public name = "elasticsearch.queryBuilder.operator.andIn.default" ; public getOperator ( ) { return "and_in" ; } public apply ( query , params ) { const { value : values , path , basePath } = params ; const isArray = Array . isArray ( values ) ; if ( isArray === false || values . length === 0 ) { throw new Error ( `You cannot filter field "${ path }" with "in" operator and not send an array of values.` ) ; } let useBasePath = false ; for ( const value of values ) { if ( typeof value !== "string" ) { useBasePath = true ; break ; } } for ( const value of values ) { query . must . push ( { term : { [ useBasePath ? basePath : path ] : value } } ) ; } } }