owc-elasticsearch
Advanced tools
Comparing version 1.0.1 to 1.0.5
@@ -124,10 +124,10 @@ /** | ||
*/ | ||
delete(id, refresh = false) { | ||
static delete(id, refresh = false) { | ||
let params = { | ||
index: this.constructor.index, | ||
type: this.constructor.type, | ||
index: this.index, | ||
type: this.type, | ||
id: id, | ||
refresh : refresh | ||
}; | ||
return this.constructor.client.delete(params); | ||
return this.client.delete(params); | ||
} | ||
@@ -141,4 +141,4 @@ | ||
*/ | ||
updateMapping() { | ||
return this.constructor.client.indices.putMapping(this.constructor.mapping); | ||
static updateMapping() { | ||
return this.client.indices.putMapping(this.mapping); | ||
} | ||
@@ -477,3 +477,2 @@ | ||
let params = buildQuery.call(this); | ||
console.log(JSON.stringify(params)); | ||
let ret = []; | ||
@@ -630,3 +629,3 @@ let result = await this.constructor.client.search(params); | ||
}; | ||
let mapping = this.mapping(); | ||
let mapping = this.constructor.mapping; | ||
let keys = Object.keys(mapping[this.constructor.type]['properties']); | ||
@@ -636,3 +635,3 @@ for(let key in this) { | ||
if(keys.indexOf(key) >= 0) { | ||
if (mapping[this.constructor.type]['properties'][key][type] == 'completion') { | ||
if (mapping[this.constructor.type]['properties'][key]["type"] == 'completion') { | ||
params['body']['doc'][key] = {'input': value}; | ||
@@ -639,0 +638,0 @@ } else { |
@@ -1,4 +0,4 @@ | ||
const ElasticClient = require("ElasticClient"); | ||
const ElasticClient = require("./ElasticClient"); | ||
const ElasticSearch = require("ElasticSearch"); | ||
const ElasticSearch = require("./ElasticSearch"); | ||
@@ -5,0 +5,0 @@ module.exports = { |
{ | ||
"name": "owc-elasticsearch", | ||
"version": "1.0.1", | ||
"version": "1.0.5", | ||
"description": "An ORM of elasticsearch indexes with built in query body builder to allow you manipulate data in elasticsearch like a relational db.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,2 +0,2 @@ | ||
# owc-elasticsearch-orm | ||
# owc-elasticsearch | ||
An ORM of elasticsearch indexes with built in query body builder to allow you manipulate data in elasticsearch like a relational db. | ||
@@ -6,3 +6,3 @@ | ||
npm i --save owc-elasticsearch-orm | ||
npm i --save owc-elasticsearch | ||
@@ -13,3 +13,3 @@ **2. Usage** | ||
const elasticsearch = require("owc-elasticsearch-orm"); | ||
const elasticsearch = require("owc-elasticsearch"); | ||
@@ -30,3 +30,3 @@ **2.2 Initialize ElasticClient** | ||
const es = require("owc-elasticsearch-orm"); | ||
const es = require("owc-elasticsearch"); | ||
@@ -268,3 +268,3 @@ class User extends es.ElasticSearch { | ||
await User.find().query([{match : {"username" : 'test'}} ]).orQuery([{match : {"username" : 'owc'}}]).andQuery({match: {"lastname": "second"}}).mustNotQuery([{match : {"username" : 'last'}}]).all(); | ||
await User.find().query([{match : {"username" : 'test'}} ]).orQuery([{match : {"username" : 'owc'}}]).andQuery({match: {"lastname": "second"}}).mustNotQuery([{match : {"username" : 'search'}}]).all(); | ||
@@ -275,4 +275,12 @@ **23. Find users whose username contains "search fu"** | ||
**24. Delete index** | ||
**24. Delete user whose id is 1** | ||
await User.delete(1); | ||
**25. Delete user whose username contains "search"** | ||
await User.find().query({match:{username: 'search'}}).deleteAll(); | ||
**26. Delete index** | ||
await User.deleteIndex(); | ||
@@ -279,0 +287,0 @@ |
@@ -79,2 +79,22 @@ const test = require('unit.js'); | ||
it("test update user", function(done) { | ||
let tmp = { | ||
id: 2, | ||
tenant_id : 3, | ||
firstname: ['second', 'abcd', 'name'], | ||
lastname: 'second user last name', | ||
email: "support2@owcmvc.com", | ||
status : 2, | ||
default : 2, | ||
username : "test search function" | ||
} | ||
User.saveUser(tmp, true).then(data => { | ||
console.log(data); | ||
test.value(data.result).is("updated"); | ||
done(null); | ||
}).catch(err => { | ||
done(err); | ||
}); | ||
}); | ||
it("test user exists expect true", function(done) { | ||
@@ -285,2 +305,25 @@ User.exists(1).then(data => { | ||
it("delete user whose id is 1", function(done) { | ||
User.delete(1).then(data => { | ||
console.log(data); | ||
test.value(data.found).is(true); | ||
done(null); | ||
}).catch(err => { | ||
done(err); | ||
}); | ||
}); | ||
it("delete user whose username has keyword 'search'", function(done) { | ||
User.find().query({match:{username: 'search'}}).deleteAll().then(data => { | ||
console.log(data); | ||
test.value(data.deleted).is(1); | ||
done(null); | ||
}).catch(err => { | ||
done(err); | ||
}); | ||
}); | ||
it("delete index expect true", function(done) { | ||
@@ -287,0 +330,0 @@ User.deleteIndex().then(data => { |
Sorry, the diff of this file is not supported yet
65263
1109
301