Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@elastic/elasticsearch

Package Overview
Dependencies
Maintainers
69
Versions
116
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

  • 8.17.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
686K
decreased by-38.51%
Maintainers
69
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

FAQs

Package last updated on 12 Dec 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc