ES文档地址:Elastic Search API DOC
下文包含了ES的Nodejs API介绍
判断index是否存在
# 接口
class Indices {
exists(params: IndicesExistsParams): Promise<any>; // 返回为Promise
}
export interface IndicesExistsParams extends GenericParams {
ignoreUnavailable?: boolean;
allowNoIndices?: boolean;
expandWildcards?: ExpandWildcards;
local?: boolean;
index: NameList; // string | string[] | boolean;
}
示例:
# 判断index名称为saas 123 saas20180503是否存在
const result = await Promise.all([
ElasticSearch.indices.exists({index:'saas'}),
ElasticSearch.indices.exists({index:['123']}),
ElasticSearch.indices.exists({index:['saas20180503']})
]);
console.log(result, typeof(result)); //[true, false, true] 'object'
# 在存在的saas saas20180503进行查询
const data = await ElasticSearch.search({index:['saas','saas20180503']});