backbone-db-elasticsearch
Advanced tools
Comparing version 0.1.6 to 0.1.7
43
index.js
@@ -206,3 +206,3 @@ var _ = require('lodash'); | ||
for (var key in indexObject) { | ||
prefixed[this.name + this.prefixSeparator + indexObject[key]]; | ||
prefixed[this.name + this.prefixSeparator + key] = indexObject[key]; | ||
} | ||
@@ -227,6 +227,8 @@ return prefixed; | ||
index: indexName, | ||
body: { | ||
settings: options.settings | ||
} | ||
body: {} | ||
}; | ||
if (options.settings) opts.body.settings = options.settings; | ||
if (options.mappings) opts.body.mappings = options.mappings; | ||
if (options.warmers) opts.body.warmers = options.warmers; | ||
debug('createIndex', opts); | ||
this.client.indices.create(opts, function(error, resp) { | ||
@@ -239,5 +241,7 @@ callback(error, resp); | ||
var indexName = this.prefixIndexKeys(options.index); | ||
this.client.indices.delete({ | ||
var opts = { | ||
index: indexName | ||
}, function(error, resp) { | ||
}; | ||
debug('deleteIndex', opts); | ||
this.client.indices.delete(opts, function(error, resp) { | ||
callback(error, resp); | ||
@@ -279,6 +283,31 @@ }); | ||
this.client.indices.putSettings(opts, callback); | ||
}, | ||
updateMapping: function(options, callback) { | ||
var indexName = this.prefixIndexKeys(options.index); | ||
var opts = { | ||
index: indexName, | ||
type: options.type, | ||
body: options.mapping | ||
}; | ||
this.client.indices.putMapping(opts, callback); | ||
}, | ||
getMapping: function(options, callback) { | ||
var indexName = this.prefixIndexKeys(options.index); | ||
var opts = { | ||
index: indexName | ||
}; | ||
this.client.indices.getMapping(opts, callback); | ||
}, | ||
deleteMapping: function(options, callback) { | ||
var indexName = this.prefixIndexKeys(options.index); | ||
var opts = { | ||
index: indexName | ||
}; | ||
this.client.indices.deleteMapping(opts, callback); | ||
} | ||
}); | ||
module.exports = ElasticSearchDb; |
{ | ||
"name": "backbone-db-elasticsearch", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "Elasticsearch driver for backbone-db", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -67,3 +67,3 @@ ## backbone-db-elasticsearch | ||
}); | ||
model.save(null, {update: true); | ||
model.save(null, {update: true}); | ||
``` | ||
@@ -114,2 +114,8 @@ | ||
This adapter is not fully backbone-db compliant, since query DSL is using Elasticsearch syntax, instead of MongoDB syntax. | ||
This adapter is not fully backbone-db compliant, since query DSL is using Elasticsearch syntax, instead of MongoDB syntax. Currently supported version of ES is 1.3.2. | ||
### Configuration | ||
Dynamic scripting should be enabled in `/usr/local/opt/elasticsearch/config/elasticsearch.yml`: | ||
script.disable_dynamic: false |
@@ -94,3 +94,3 @@ var setup = require('./setup'); | ||
it('should update index settings', function(next) { | ||
it.skip('should update index settings', function(next) { | ||
var indexSettings = { | ||
@@ -114,2 +114,32 @@ mappings: { | ||
it('should update index mappings', function(next) { | ||
var mapping = { | ||
'mytype': { | ||
properties: { | ||
message: { | ||
type: 'string', | ||
store: true, | ||
analyzer: 'uax_url_email' | ||
} | ||
} | ||
} | ||
}; | ||
this.db.updateMapping({ | ||
index: 'foobar', | ||
type: 'mytype', | ||
mapping: mapping | ||
}, function(err) { | ||
next(err); | ||
}); | ||
}); | ||
it('should get mapping', function(next) { | ||
this.db.getMapping({ | ||
index: 'foobar' | ||
}, function(err, resp) { | ||
should.exist(resp); | ||
next(err); | ||
}); | ||
}); | ||
it('should delete index', function(next) { | ||
@@ -116,0 +146,0 @@ this.db.deleteIndex({ |
@@ -179,3 +179,2 @@ var setup = require('./setup'); | ||
.then(function() { | ||
//console.log(collection.toJSON()); | ||
collection.at(0).get('content').name.should.equal('efgabc'); | ||
@@ -182,0 +181,0 @@ }); |
30874
824
119