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

moleculer-elasticsearch

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

moleculer-elasticsearch

Elasticsearch service for Moleculer.

  • 1.1.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Moleculer logo

moleculer-elasticsearch NPM version

Elasticsearch service for Moleculer.

Features

  • support 5.4 API
  • straightforward actions & params

Install

$ npm install moleculer-elasticsearch --save

Usage

Running Elasticsearch server for development

 $ docker run -p 9200:9200 -e "http.host=0.0.0.0" -e "transport.host=127.0.0.1" docker.elastic.co/elasticsearch/elasticsearch:5.5.0

More information about Elasticsearch Docker image.

Start service

"use strict";

let { ServiceBroker } 	= require("moleculer");
let ESService 			= require("moleculer-elasticsearch");

// Create broker
let broker = new ServiceBroker({ logger: console });

// Create service
broker.createService({
    mixins: [ESService],
    settings: {
        elasticsearch: {
            node: "http://elastic:changeme@<docker-hostname>:9200",
        }
    }
});

broker.start()

    // Create a document
    .then(() => broker.call("elasticsearch.create", { 
        index: "demo", 
        id: "1", 
        body: { name: "John Doe", age: 36 }
    }))

    .delay(500)

    // Search documents
    .then(() => broker.call("elasticsearch.search", { 
        body: {
            query: {
                match: {
                    name: "john"
                }
            }
        } 
    }).then(res => console.log("Hits:", res.hits.hits)))
    
    // Remove document
    .then(() => broker.call("elasticsearch.delete", { index: "demo", id: "1" }))

Settings

PropertyTypeDefaultDescription
elasticsearchObjectrequiredElasticsearch constructor options. More options
elasticsearch.nodeStringrequiredHost

Actions

bulk

Perform many index/delete operations in a single API call.

More info: https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-bulk

Parameters

PropertyTypeDefaultDescription
indexString-Default index for items which don’t provide one
bodyArrayrequiredThe request body, as either an array of objects or new-line delimited JSON objects

Results

Type: Object

Elasticsearch response object

create

Adds a typed JSON document in a specific index, making it searchable. If a document with the same index, type, and id already exists, an error will occur.

More info: https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-create

Parameters

PropertyTypeDefaultDescription
indexStringrequiredThe name of the index
idStringrequiredDocument ID
bodyObjectrequiredThe request body, as either JSON or a JSON serializable object.

Results

Type: Object

Elasticsearch response object

get

Get a typed JSON document from the index based on its id.

More info: https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-get

Parameters

PropertyTypeDefaultDescription
indexStringrequiredThe name of the index
idString-Document ID

Results

Type: Object

Found document

update

Update (reindex) the document with the specified unique id.

More info: https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-update

Parameters

PropertyTypeDefaultDescription
indexStringrequiredThe name of the index
idStringrequiredDocument ID
bodyObjectrequiredThe request body, as either JSON or a JSON serializable object.

Results

Type: Object

Elasticsearch response object

delete

Delete the document with the specified unique id.

More info: https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-delete

Parameters

PropertyTypeDefaultDescription
indexStringrequiredThe name of the index
idStringrequiredDocument ID

Results

Type: Object

Elasticsearch response object

Return documents matching a query, aggregations/facets, highlighted snippets, suggestions, and more.

More info: https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-search

Parameters

PropertyTypeDefaultDescription
indexString, Array.<String>requiredA comma-separated list of index names to search; use _all or empty string to perform the operation on all indices
qString-Query in the Lucene query string syntax.
bodyObject-The request body, as either JSON or a JSON serializable object.

Results

Type: Object

Elasticsearch response object

count

Get the number of documents for the cluster, index, type, or a query.

More info: https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-count

Parameters

PropertyTypeDefaultDescription
indexString, Array.<String>requiredA comma-separated list of indices to restrict the results.
qString-Query in the Lucene query string syntax.
bodyObject-The request body, as either JSON or a JSON serializable object.

Results

Type: Object

Elasticsearch response object

call

Call any Elasticsearch API

More info: https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html

Parameters

PropertyTypeDefaultDescription
apiStringrequiredThe name of the API
paramsObjectrequiredParams of request

Results

Type: Object

Elasticsearch response

Methods

Test

$ npm test

In development with watching

$ npm run ci

License

The project is available under the MIT license.

Contact

Copyright (c) 2016-2019 MoleculerJS

@moleculerjs @MoleculerJS

Keywords

FAQs

Package last updated on 23 Nov 2022

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