Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
elasticsearch
Advanced tools
The elasticsearch npm package is a client library for interacting with Elasticsearch, a distributed search and analytics engine. This package allows developers to perform a variety of operations such as indexing documents, searching, and managing indices within an Elasticsearch cluster.
Indexing Documents
This feature allows you to index documents into an Elasticsearch index. The code sample demonstrates how to create a client, connect to an Elasticsearch node, and index a document into 'my-index'.
const { Client } = require('@elastic/elasticsearch');
const client = new Client({ node: 'http://localhost:9200' });
async function run() {
await client.index({
index: 'my-index',
document: {
title: 'Test Document',
content: 'This is a test document.'
}
});
console.log('Document indexed');
}
run().catch(console.log);
Searching Documents
This feature allows you to search for documents within an Elasticsearch index. The code sample demonstrates how to search for documents in 'my-index' where the title matches 'Test'.
const { Client } = require('@elastic/elasticsearch');
const client = new Client({ node: 'http://localhost:9200' });
async function run() {
const result = await client.search({
index: 'my-index',
query: {
match: { title: 'Test' }
}
});
console.log(result.hits.hits);
}
run().catch(console.log);
Managing Indices
This feature allows you to manage indices in Elasticsearch. The code sample demonstrates how to create a new index called 'my-new-index'.
const { Client } = require('@elastic/elasticsearch');
const client = new Client({ node: 'http://localhost:9200' });
async function run() {
await client.indices.create({
index: 'my-new-index'
});
console.log('Index created');
}
run().catch(console.log);
Mongoose is an ODM (Object Data Modeling) library for MongoDB and Node.js. It provides a schema-based solution to model your application data. While it is similar in that it interacts with a database, it is specific to MongoDB and offers features like schema validation and middleware, which are not provided by the elasticsearch package.
Redis is a fast, open-source, in-memory key-value data store. The redis npm package allows you to interact with a Redis database. While it offers some overlapping functionalities like data storage and retrieval, it is designed for different use cases such as caching and real-time analytics, unlike Elasticsearch which is optimized for full-text search and complex queries.
Couchbase is a distributed NoSQL cloud database. The couchbase npm package allows you to interact with a Couchbase server. It offers similar functionalities like indexing and querying documents but is designed for high-performance applications requiring low-latency data access, whereas Elasticsearch is optimized for search and analytics.
This is a Node.js module for the elasticsearch REST API.
var elasticsearch = require('elasticsearch');
var es = elasticsearch({index: 'kitteh'});
es.query({query: {field: {field1: 'hai'}}}, function(err, results) {
console.log(results);
});
Unless otherwise stated, all callbacks are called with cb(err, res)
, with res
being the parsed JSON response from elasticsearch.
Shortcut for elasticsearch.createClient(opts)
.
Returns a new client object.
Options:
index
: The name of the index to act upon.We'll call the returned client es
.
Get the status of the index. Maps to GET /index/_status.
Add a document to the index. Maps to PUT /index/type/id or POST /index/type.
Options:
id
: Optional ID for the document. A UUID will be chosen by elasticsearch if no ID is specified.type
: Optional type for the document (default: doc
).refresh
: Set this to true to refresh the index after add.Delete a document or documents from the index. Maps to DELETE /index/type/id.
Options:
id
: Optional ID for the document. All documents of this type will be deleted if no ID is specified.type
: Optional type for the document (default: doc
).refresh
: Set this to true to refresh the index after delete.Get a document from the index. Maps to GET /index/type/id.
Options:
id
: ID for the document.type
: Optional type for the document (default: doc
).Query the index. Maps to POST /index/_search.
Get the count of a query result set. Maps to POST /index/_count.
Query all indexes. Maps to POST /_search.
Put a new or updated river. Maps to PUT /_river/name/_meta.
Options:
name
: Name for the river.Get a river. Maps to GET /_river/name/_meta.
Delete a river. Maps to DELETE /_river/name/.
Put a new or updated mapping. Maps to PUT /index/name/_mapping.
name
is defined by config.name
and mapping
by config.mapping
.
Get a mapping. Maps to GET /index/type/_mapping.
If type is an array its values will be joined.
Delete a mapping. Maps to DELETE /index/name/_mapping.
name
is defined by config.name
.
Returns a new index object.
Options:
name
: The name of the index to act upon.We'll call the returned index index
.
Get the status of the index. Maps to GET /index/_status.
Refresh the index. Maps to POST /index/_refresh.
Create the index. Maps to PUT /index/ or POST /index/ depending on the existence of config.mappings
.
Delete the index. Maps to DELETE /index.
Returns a new cluster object.
We'll call the returned cluster cluster
.
Get the status of the cluster. Maps to GET /_status.
Delete all indices in this cluster. Maps to multiple calls to DELETE /index/.
Get health of the cluster. Maps to GET _cluster/health.
Options map to query parameters.
npm install
npm test
MIT
FAQs
The official low-level Elasticsearch client for Node.js and the browser.
The npm package elasticsearch receives a total of 119,931 weekly downloads. As such, elasticsearch popularity was classified as popular.
We found that elasticsearch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.