Elasticsearch is a distributed search and analytics engine built on Apache Lucene. Since its release in 2010, Elasticsearch has quickly become the most popular search engine and is commonly used for log analytics, full-text search, security intelligence, business analytics, and operational intelligence use cases.
Questions
Q. Is there any way to use this in UI, like for typeahead and all?
Example with Nodejs
npm install @elastic/elasticsearchconst { Client } = require('@elastic/elasticsearch');
// Create a new Elasticsearch client
const client = new Client({ node: 'http://localhost:9200' });
// Index a document
async function indexDocument() {
const document = {
title: 'The Great Gatsby',
author: 'F. Scott Fitzgerald',
description: 'A novel about the American Dream in the Jazz Age.'
};
const response = await client.index({
index: 'books',
body: document
});
console.log('Document indexed:', response.body);
}
// Search documents
async function searchDocuments() {
const searchTerm = 'American Dream';
const response = await client.search({
index: 'books',
body: {
query: {
match: {
description: searchTerm
}
}
}
});
console.log('Search results:', response.body.hits.hits);
}
/*
Document indexed: { _index: 'books', _type: '_doc', _id: 'abc123', _version: 1, result: 'created', ... }
Search results: [ { _index: 'books', _type: '_doc', _id: 'abc123', _score: 0.123, _source: { title: 'The Great Gatsby', author: 'F. Scott Fitzgerald', description: 'A novel about the American Dream in the Jazz Age.' } } ]
*/
// Call the functions
async function run() {
await indexDocument();
await searchDocuments();
}
run().catch(console.error);