1.0.5 • Published 3 years ago

adonis-v5-elasticsearch v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Adonis Elastic Search

This service provider makes it easier to integrate and to work with the official Elasticsearch client library for Node.js

It is built on top of @elastic/elasticsearch and proxies all the methods keeping them 100% original. So you can follow official Elasticsearch API reference.

Installation

npm install adonis-v5-elasticsearch

Set the environment variable

Make sure you set the ELASTIC_SEARCH_URL environment variable in your .env file. This will be used to access your Elasticsearch server.

ELASTIC_SEARCH_URL=http://localhost:9200

Registering the provider

Make sure to register the provider inside .adonisrc.json file.

{
  // ...
  "providers": {
    // "...",
    "adonis-v5-elasticsearch/providers/ElasticProvider"
  },
  // ...
}

That's all! Now you can use the provider by pulling it from IoC container

import { ApiResponse } from "@elastic/elasticsearch";
import Elastic from "@ioc:Elastic";

const response: ApiResponse = await Elastic.search({
  index: "my-index",
  body: {
    query: {
      match_all: {},
    },
  },
});

Paginate results the Adonis way!

The Elastic.paginate() helper will paginate the results and return the same payload as Lucid's pagination method.

import { ApiResponse } from "@elastic/elasticsearch";
import Elastic from "@ioc:Elastic";

const response: ApiResponse = await Elastic.search({
  index: "my-index",
  body: {
    query: {
      match_all: {},
    },
  },
});

return Elastic.paginate(response);

Contributing

You are more than welcome to contribute to adonis-v5-elasticsearch. Just submit changes via pull request and I will review them before merging.

  1. Fork it! 🤙

  2. Create your feature branch: git checkout -b my-new-feature

  3. Commit your changes: git commit -am "Add some feature"

  4. Push to the branch: git push origin my-new-feature

  5. Submit a pull request 👍

License

The Adonis Elasticsearch Service Provider is MIT licensed.

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago