import { Cluster } from './cluster' ; import { IndexNotFoundError } from './errors' ; import { HttpExecutor , HttpMethod , HttpServiceType } from './httpexecutor' ; import { RequestSpan } from './tracing' ; import { NodeCallback , PromiseHelper } from './utilities' ; category export interface ISearchIndex { /**
     * The name of the search index.
     */ name : string ; } category export class SearchIndex { /**
     * The name of the search index.
     */ name : string ; internal constructor ( data ) { this . name = data . name ; } } category export interface GetSearchIndexOptions { /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; } category export interface GetAllSearchIndexesOptions { /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; } category export interface UpsertSearchIndexOptions { /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; } category export interface DropSearchIndexOptions { /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; } category export interface GetSearchIndexedDocumentsCountOptions { /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; } category export interface PauseSearchIngestOptions { /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; } category export interface ResumeSearchIngestOptions { /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; } category export interface AllowSearchQueryingOptions { /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; } category export interface DisallowSearchQueryingOptions { /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; } category export interface FreezeSearchPlanOptions { /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; } category export interface UnfreezeSearchPlanOptions { /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; } category export interface AnalyzeSearchDocumentOptions { /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; } category export class SearchIndexManager { private _cluster : Cluster ; internal constructor ( cluster ) { this . _cluster = cluster ; } private get _http ( ) { return new HttpExecutor ( this . _cluster . _getClusterConn ( ) ) ; } param indexName param options param callback async getIndex ( indexName , options ? , callback ? ) { if ( options instanceof Function ) { callback = arguments [ 1 ] ; options = undefined ; } if ( ! options ) { options = { } ; } const parentSpan = options . parentSpan ; const timeout = options . timeout ; return PromiseHelper . wrapAsync ( async ( ) => { const res = await this . _http . request ( { type : HttpServiceType . Search , method : HttpMethod . Get , path : `/api/index/${ indexName }` , parentSpan : parentSpan , timeout : timeout , } ) ; if ( res . statusCode !== 200 ) { throw new IndexNotFoundError ( ) ; } return JSON . parse ( res . body . toString ( ) ) ; } , callback ) ; } param options param callback async getAllIndexes ( options ? , callback ? ) { if ( options instanceof Function ) { callback = arguments [ 0 ] ; options = undefined ; } if ( ! options ) { options = { } ; } const parentSpan = options . parentSpan ; const timeout = options . timeout ; return PromiseHelper . wrapAsync ( async ( ) => { const res = await this . _http . request ( { type : HttpServiceType . Search , method : HttpMethod . Get , path : `/api/index` , parentSpan : parentSpan , timeout : timeout , } ) ; if ( res . statusCode !== 200 ) { throw new Error ( 'failed to fetch search indices' ) ; } return JSON . parse ( res . body . toString ( ) ) ; } , callback ) ; } param indexDefinition param options param callback async upsertIndex ( indexDefinition , options ? , callback ? ) { if ( options instanceof Function ) { callback = arguments [ 1 ] ; options = undefined ; } if ( ! options ) { options = { } ; } const indexName = indexDefinition . name ; const parentSpan = options . parentSpan ; const timeout = options . timeout ; return PromiseHelper . wrapAsync ( async ( ) => { const res = await this . _http . request ( { type : HttpServiceType . Search , method : HttpMethod . Put , path : `/api/index/${ indexName }` , contentType : 'application/json' , body : JSON . stringify ( indexDefinition ) , parentSpan : parentSpan , timeout : timeout , } ) ; if ( res . statusCode !== 200 ) { throw new Error ( 'failed to create index' ) ; } } , callback ) ; } param indexName param options param callback async dropIndex ( indexName , options ? , callback ? ) { if ( options instanceof Function ) { callback = arguments [ 1 ] ; options = undefined ; } if ( ! options ) { options = { } ; } const parentSpan = options . parentSpan ; const timeout = options . timeout ; return PromiseHelper . wrapAsync ( async ( ) => { const res = await this . _http . request ( { type : HttpServiceType . Search , method : HttpMethod . Delete , path : `/api/index/${ indexName }` , parentSpan : parentSpan , timeout : timeout , } ) ; if ( res . statusCode !== 200 ) { throw new Error ( 'failed to delete search index' ) ; } return JSON . parse ( res . body . toString ( ) ) ; } , callback ) ; } param indexName param options param callback async getIndexedDocumentsCount ( indexName , options ? , callback ? ) { if ( options instanceof Function ) { callback = arguments [ 1 ] ; options = undefined ; } if ( ! options ) { options = { } ; } const parentSpan = options . parentSpan ; const timeout = options . timeout ; return PromiseHelper . wrapAsync ( async ( ) => { const res = await this . _http . request ( { type : HttpServiceType . Search , method : HttpMethod . Get , path : `/api/index/${ indexName }/count` , parentSpan : parentSpan , timeout : timeout , } ) ; if ( res . statusCode !== 200 ) { throw new Error ( 'failed to get search indexed documents count' ) ; } return JSON . parse ( res . body . toString ( ) ) ; } , callback ) ; } param indexName param options param callback async pauseIngest ( indexName , options ? , callback ? ) { if ( options instanceof Function ) { callback = arguments [ 1 ] ; options = undefined ; } if ( ! options ) { options = { } ; } const parentSpan = options . parentSpan ; const timeout = options . timeout ; return PromiseHelper . wrapAsync ( async ( ) => { const res = await this . _http . request ( { type : HttpServiceType . Search , method : HttpMethod . Post , path : `/api/index/${ indexName }/ingestControl/pause` , parentSpan : parentSpan , timeout : timeout , } ) ; if ( res . statusCode !== 200 ) { throw new Error ( 'failed to pause search index ingestion' ) ; } } , callback ) ; } param indexName param options param callback async resumeIngest ( indexName , options ? , callback ? ) { if ( options instanceof Function ) { callback = arguments [ 1 ] ; options = undefined ; } if ( ! options ) { options = { } ; } const parentSpan = options . parentSpan ; const timeout = options . timeout ; return PromiseHelper . wrapAsync ( async ( ) => { const res = await this . _http . request ( { type : HttpServiceType . Search , method : HttpMethod . Post , path : `/api/index/${ indexName }/ingestControl/resume` , parentSpan : parentSpan , timeout : timeout , } ) ; if ( res . statusCode !== 200 ) { throw new Error ( 'failed to resume search index ingestion' ) ; } } , callback ) ; } param indexName param options param callback async allowQuerying ( indexName , options ? , callback ? ) { if ( options instanceof Function ) { callback = arguments [ 1 ] ; options = undefined ; } if ( ! options ) { options = { } ; } const parentSpan = options . parentSpan ; const timeout = options . timeout ; return PromiseHelper . wrapAsync ( async ( ) => { const res = await this . _http . request ( { type : HttpServiceType . Search , method : HttpMethod . Post , path : `/api/index/${ indexName }/queryControl/allow` , parentSpan : parentSpan , timeout : timeout , } ) ; if ( res . statusCode !== 200 ) { throw new Error ( 'failed to allow search index quering' ) ; } } , callback ) ; } param indexName param options param callback async disallowQuerying ( indexName , options ? , callback ? ) { if ( options instanceof Function ) { callback = arguments [ 1 ] ; options = undefined ; } if ( ! options ) { options = { } ; } const parentSpan = options . parentSpan ; const timeout = options . timeout ; return PromiseHelper . wrapAsync ( async ( ) => { const res = await this . _http . request ( { type : HttpServiceType . Search , method : HttpMethod . Post , path : `/api/index/${ indexName }/queryControl/disallow` , parentSpan : parentSpan , timeout : timeout , } ) ; if ( res . statusCode !== 200 ) { throw new Error ( 'failed to disallow search index quering' ) ; } } , callback ) ; } param indexName param options param callback async freezePlan ( indexName , options ? , callback ? ) { if ( options instanceof Function ) { callback = arguments [ 1 ] ; options = undefined ; } if ( ! options ) { options = { } ; } const parentSpan = options . parentSpan ; const timeout = options . timeout ; return PromiseHelper . wrapAsync ( async ( ) => { const res = await this . _http . request ( { type : HttpServiceType . Search , method : HttpMethod . Post , path : `/api/index/${ indexName }/planFreezeControl/freeze` , parentSpan : parentSpan , timeout : timeout , } ) ; if ( res . statusCode !== 200 ) { throw new Error ( 'failed to freeze search index plan' ) ; } } , callback ) ; } param indexName param document param options param callback async analyzeDocument ( indexName , document , options ? , callback ? ) { if ( options instanceof Function ) { callback = arguments [ 2 ] ; options = undefined ; } if ( ! options ) { options = { } ; } const parentSpan = options . parentSpan ; const timeout = options . timeout ; return PromiseHelper . wrapAsync ( async ( ) => { const res = await this . _http . request ( { type : HttpServiceType . Search , method : HttpMethod . Post , path : `/api/index/${ indexName }/analyzeDoc` , body : JSON . stringify ( document ) , parentSpan : parentSpan , timeout : timeout , } ) ; if ( res . statusCode !== 200 ) { throw new Error ( 'failed to perform search index document analysis' ) ; } return JSON . parse ( res . body . toString ( ) ) . analyze ; } , callback ) ; } }