An elasticsearch database handler for jsonapi-server
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Coverage Status Build Status npm version Code Climate Dependencies Status


jsonapi-server-elasticsearch is a Elasticsearch backed data store for jsonapi-server.

This project conforms to the specification laid out in the jsonapi-server handler documentation.


var ElasticsearchStore = require("jsonapi-store-elasticsearch");

  resource: "comments",
  handlers: new ElasticsearchStore({
    host: "localhost:9200"


  • Search, Find, Create, Delete, Update
  • Filtering, Sorting, Pagination

Getting to Production

Getting this data store to production isn't too bad...

  1. Bring up your Elasticsearch stack.
  2. Create an index, give it a sensible name.
  3. Create an alias for your index to the name "jsonapi".
  4. Create the mapping for your resource. If you rely on the automatic mapping, you won't be able to sort on any attributes, and thus pagination won't work either.
  5. Deploy your code.
  6. Celebrate.

You'll probably want to override this handler's search functionality in order to achieve high-performance queries. That may look something like this:

var efficientHandler = new ElasticsearchStore({
  host: "localhost:9200"
// the next function correlates with the jsonapi-server handler documentation:
// = function(request, callback) {
  // within this scope, this._db is the Elasticsearch client
  var efficientQuery = buildAwesomeQuery();, callback);

  resource: "comments",
  handlers: efficientHandler

When making schema changes...

If you are only adding new attributes, you can push in a mapping for the new attribute, deploy your code changes and celebrate.

If you are making destructive changes, you'll need to create a new index, add a fresh mapping, migrate data into it and finally swap the "jsonapi" alias to point to your new index. You can read this section on how to switch aliases around: