🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

@elastic/elasticsearch

Package Overview
Dependencies
Maintainers
67
Versions
127
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@elastic/elasticsearch

The official Elasticsearch client for Node.js

9.0.1
latest
Source
npm
Version published
Weekly downloads
1.3M
-0.34%
Maintainers
67
Weekly downloads
 
Created

What is @elastic/elasticsearch?

@elastic/elasticsearch is the official Node.js client for Elasticsearch. It allows developers to interact with Elasticsearch clusters, perform CRUD operations, search, and manage indices, among other functionalities.

What are @elastic/elasticsearch's main functionalities?

Connecting to Elasticsearch

This code demonstrates how to create a new client instance to connect to an Elasticsearch cluster running on localhost.

const { Client } = require('@elastic/elasticsearch');
const client = new Client({ node: 'http://localhost:9200' });

Indexing Documents

This code sample shows how to index a document into an Elasticsearch index named 'my-index'.

async function run() {
  await client.index({
    index: 'my-index',
    id: '1',
    body: {
      title: 'Test Document',
      content: 'This is a test document.'
    }
  });
}
run().catch(console.log);

Searching Documents

This code demonstrates how to search for documents in the 'my-index' index that match the term 'Test' in the title field.

async function run() {
  const { body } = await client.search({
    index: 'my-index',
    body: {
      query: {
        match: { title: 'Test' }
      }
    }
  });
  console.log(body.hits.hits);
}
run().catch(console.log);

Managing Indices

This code sample shows how to create a new index named 'my-new-index' in Elasticsearch.

async function run() {
  await client.indices.create({
    index: 'my-new-index'
  });
}
run().catch(console.log);

Other packages similar to @elastic/elasticsearch

Keywords

elasticsearch

FAQs

Package last updated on 25 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts