Elasticsearch Module
Elasticsearch is a search engine based on the Lucene library. It provides a distributed, multitenant-capable full-text search engine with an HTTP web interface and schema-free JSON documents.
Install
npm install @testcontainers/elasticsearch --save-dev
Examples
it.each(images)("should create an index with %s", async (image) => {
const container = await new ElasticsearchContainer(image).start();
const client = new Client({
node: container.getHttpUrl(),
auth: { username: container.getUsername(), password: container.getPassword() },
});
await client.indices.create({ index: "people" });
expect(await client.indices.exists({ index: "people" })).toBe(true);
await container.stop();
});
it("should index a document", async () => {
const container = await new ElasticsearchContainer(IMAGE).start();
const client = new Client({
node: container.getHttpUrl(),
auth: { username: container.getUsername(), password: container.getPassword() },
});
const document = {
id: "1",
name: "John Doe",
};
await client.index({
index: "people",
id: document.id,
document,
});
expect((await client.get({ index: "people", id: document.id }))._source).toStrictEqual(document);
await container.stop();
});