UNPKG

giganet_conecta

Version:

Aplicação com o fim de facilitar conexões com APi's e Banco de Dados (MySql & Mongo).

57 lines (51 loc) 1.52 kB
class IndicesService { constructor(client) { this.client = client; } // Criar um índice async createIndex({ index }) { try { return await this.client.indices.create({ index }); } catch (error) { throw new Error(`Erro ao criar índice (${index}): ${error}`); } } // Criar um índice com mapeamento async getAllIndices() { try { const response = await this.client.cat.indices({ format: "json" }); return response.map((index) => index.index); // Retorna apenas os nomes dos índices } catch (error) { throw new Error(`Erro ao buscar índices: ${error}`); } } // Verificar se um índice existe async indexExists({ index }) { try { return await this.client.indices.exists({ index }); } catch (error) { throw new Error(`Erro ao verificar índice (${index}): ${error}`); } } // Deletar um índice async deleteIndex({ index }) { try { return await this.client.indices.delete({ index }); } catch (error) { throw new Error(`Erro ao deletar índice (${index}): ${error}`); } } // Atualizar mapeamento de um índice async updateMapping({ index, newMapping }) { try { return await this.client.indices.putMapping({ index, body: newMapping }); } catch (error) { throw new Error( `Erro ao atualizar mapeamento do índice (${index}): ${error}` ); } } }; module.exports = { IndicesService, };