elasticsearch adapter for Ember Data
JavaScript Ruby
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.


Ember Data Adapter for elasticsearch

This library provides an adapter for the Ember Data persistence framework for Ember.js, allowing to store application models as JSON documents in elasticsearch.

It handles the full model lifecycle (create/read/update/delete), in the same way as the DS.RESTAdapter bundled with Ember Data.

It does not provide support for any Rails-like has_many associations and probably never will.

It does not provide support for the bulk Ember Data API, yet.


First, load the ember-data/lib/adapters/elasticsearch_adapter.js file in your application.

Use the adapter in your application's store:

var App = Em.Application.create();

App.store = DS.Store.create({
  revision: 4,
  adapter: DS.ElasticSearchAdapter.create({url: 'http://localhost:9200'})

To define a model in your application, use the standard Ember Data API:

App.Person = DS.Model.extend({
  name: DS.attr('string')

Define an index and type for the adapter as the model's url property:

  url: 'people/person'

To create a new record:

App.Person.createRecord({ id: 1, name: "John" });
App.Person.createRecord({ id: 2, name: "Mary" });

To load models from the store, use the find method:

var people = App.Person.find();
people.toArray().map( function(person) { return person.get("name") } );
// => ["John", "Mary"]

To load a single model by ID:

var person = App.Person.find( 1 );
// => "John"

To load multiple models by their IDs, pass them as an Array:

var people = App.Person.find( [2, 1] );
people.toArray().map( function(person) { return person.get("name") } );
// => ["Mary", "John"]

To load models by an elasticsearch query, pass it as an Object:

var people = App.Person.find( {query: { query_string: { query: "john" } }} );
// => 1

To persist model changes to the store, use the store's commit method:

person.set("name", "Frank");

To remove the record from the store:


Note, that all the methods are asynchronous, so the returned object is empty; bindings and observers take care of updating the object with loaded data in an Ember.js application.

See the Ember Data documentation for more information.

Example Application

The library includes an example “todos” application, as required by law.


The library comes with a QUnit-based integration test suite in ember-data/test/elasticsearch_adapter_tests.js.

Apart from running it in the browser, you can run it on the command line with the PhantomJS JavaScript runtime via a Rake task:

rake test

Karel Minarik and contributors