@bothive/helpers
Version:
Collection of helper functions mainly used inside bothive-core project
70 lines (69 loc) • 2.12 kB
TypeScript
import { IBulkResponse, IChangeAction, IDeleteAction, ISearchCount, ISearchResult, IUpdateAction } from "../interfaces/elastic.interfaces";
interface IAliasApiConfig {
count: string;
search: string;
create: string;
update: (index: string) => string;
updateQuery: string;
deleteQuery: string;
createBulk: string;
}
declare class ElasticAliasHelper {
apiKey: string;
apiConfig: IAliasApiConfig;
private static instance;
constructor({ apiKey, apiConfig }: {
apiKey: string;
apiConfig: any;
});
static getInstance: ({ apiKey, apiConfig }: {
apiKey: string;
apiConfig: any;
}) => ElasticAliasHelper;
post: ({ url, apiKey, payload }: {
url: string;
apiKey: string;
payload: any;
}) => Promise<any>;
postNdJson: ({ url, apiKey, payload }: {
url: string;
apiKey: string;
payload: string;
}) => Promise<any>;
searchDocumentById: ({ id }: {
id: string;
}) => Promise<ISearchResult>;
countByQuery: ({ query }: {
query: any;
}) => Promise<ISearchCount>;
searchByQuery: <T = ISearchResult>({ query, size, from, sort, aggs, }: {
query: any;
size?: number | undefined;
from?: number | undefined;
sort?: any;
aggs?: any;
}) => Promise<T>;
updateDocumentWithUpsert: ({ id, payload, index, routing, }: {
id: string;
payload: any;
index?: string | undefined;
routing?: string | undefined;
}) => Promise<IChangeAction>;
updateByQuery: ({ query, script, refresh, }: {
query: any;
script: any;
refresh?: boolean | undefined;
}) => Promise<IUpdateAction>;
deleteByQuery: ({ query }: {
query: any;
}) => Promise<IDeleteAction>;
insertBulk: ({ bulkPayload }: {
bulkPayload: string;
}) => Promise<IBulkResponse>;
create: ({ id, payload, routing, }: {
id: string;
payload: any;
routing?: string | undefined;
}) => Promise<IChangeAction>;
}
export default ElasticAliasHelper;