npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

moleculer-elasticsearch

v1.1.8

Published

Elasticsearch service for Moleculer.

Downloads

1,189

Readme

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

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | | elasticsearch | Object | required | Elasticsearch constructor options. More options | | elasticsearch.node | String | required | Host |

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

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | | index | String | - | Default index for items which don’t provide one | | body | Array | required | The 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

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | | index | String | required | The name of the index | | id | String | required | Document ID | | body | Object | required | The 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

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | | index | String | required | The name of the index | | id | String | - | 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

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | | index | String | required | The name of the index | | id | String | required | Document ID | | body | Object | required | The 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

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | | index | String | required | The name of the index | | id | String | required | Document ID |

Results

Type: Object

Elasticsearch response object

search

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

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | | index | String, Array.<String> | required | A comma-separated list of index names to search; use _all or empty string to perform the operation on all indices | | q | String | - | Query in the Lucene query string syntax. | | body | Object | - | 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

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | | index | String, Array.<String> | required | A comma-separated list of indices to restrict the results. | | q | String | - | Query in the Lucene query string syntax. | | body | Object | - | 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

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | | api | String | required | The name of the API | | params | Object | required | Params 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