8000 GitHub - cllu/elasticstore: A high-level MongoDB-like API for ElasticSearch
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

cllu/elasticstore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ElasticStore

ElasticStore provides a high-level MongoDB-like API for ElasticSearch. It aims to be minimal.

Installation

$ npm install elasticstore

Usage

var elasticstore = require('elasticstore');
var store = new elasticstore.Store();

function Post(data) {
  elasticstore.Node.call(this, data);
}

Post._type = 'post';
Post._schema = {
  title: String,
  created: {type: Date, default: Date.now}
};

require('util').inherits(Post, Node);

store.registerType(Post);

Post.insert({
  title: 'Hello world'
}).then(function(post) {
  console.log(post);
});

Design

A store is corresponding to an index. A model is corresponding to a document type in ElasticSearch.

Store methods

  • connect(), connect to ElasticSearch
  • model(name, schema), create a new model
  • registerType(Type), to create a subclass of Node, include a call to util.inherits(Type, Node).

Node methods

Access the Node class by store.Node.

  • getContext

  • getStore

  • getStoreClient

  • getIndex

  • getType

  • find(q), find all matching document. if q is null, return all documents

  • findById(id), (get is aliased) find the document with the given id

  • save(doc_or_docs_array), insert a new document to this model

  • updateById(id, values)

  • removeById(id), (remove is aliased) remove all documents in this model

  • count(q), return the number of documents matching the query

  • createInstance(data), create a new document of this model

To create a subclass, use the following snippet:

function Post() {
  Node.call(this);
}
Node.registerType(Post);

Then you need to access the methods by Post.findById etc.

Model instance methods

You can create a new Model instance by new Model().

  • getContext()
  • save()
  • remove()
  • update()

Test

ORG_PKG=/Users/cllu/Projects/OrganizedApp/ ./vendor/elasticsearch-1.4.4/bin/elasticsearch -D es.config=/Users/cllu/Projects/OrganizedApp/etc/elasticsearch/elasticsearch.yml

$ gulp test

Gothas

Index refresh

After ElasticSearch indexes a document, it needs some time before the document is searchable. To simplify the logic, the save() method has a refresh optional parameter which is True by default.

Mapping

Ensure to set index.mapping.coerce: false so that ES will not try to coerce numerical values.

About

A high-level MongoDB-like API for ElasticSearch

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0