Skip to content

Commit

Permalink
Merge pull request #66 from rmomii/v0.6.0
Browse files Browse the repository at this point in the history
Added support for ElasticSearch 5.5.x
  • Loading branch information
brozeph committed Oct 19, 2017
2 parents 96dde44 + 93bd368 commit 2eb92e1
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 608 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
@@ -1,14 +1,12 @@
language: node_js
node_js:
- "0.10"
- "0.12"
- "4.2"
services: elasticsearch
before_install:
- sudo service elasticsearch stop
# - sudo apt-get upgrade elasticsearch
- wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.7.0.deb
- sudo dpkg -i --force-confnew elasticsearch-1.7.0.deb
- wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.deb
- sudo dpkg -i --force-confnew elasticsearch-5.5.0.deb
- sudo service elasticsearch start
after_success:
- npm install -g coveralls
Expand Down
12 changes: 12 additions & 0 deletions HISTORY.md
@@ -1,3 +1,15 @@
# v0.6.0 / 2017-10-02

* Modified to support ElasticSearch 5.5.x
* `indices.createIndex` method adjusted to only call `put` (deprecated `post`)
* `indices.optimize` method deprecated
* `indices.status` method deprecated
* `Warmers` deprecated
* `Percolators` deprecated
* `scan` search_type deprecated
* `and` filter deprecate and replaced by `bool` query
* unit and functional tests udpated

# v0.5.2 / 2016-10-05

* Added fix for scenario where `_index` and `_type` overrides would not always work (Issue #62)
Expand Down
48 changes: 3 additions & 45 deletions README.md
Expand Up @@ -2,6 +2,8 @@

This is a Node.js module for the [elasticsearch](http://www.elasticsearch.org/) REST API.

NOTE: `node-es` `v0.6` and newer work with ElasticSearch 5 and up. For older versions of ElasticSearch, prior versions of `node-es` should be used.

[![Build Status](https://travis-ci.org/ncb000gt/node-es.png)](https://travis-ci.org/ncb000gt/node-es) [![Coverage Status](https://coveralls.io/repos/ncb000gt/node-es/badge.png)](https://coveralls.io/r/ncb000gt/node-es)

## Install
Expand Down Expand Up @@ -412,22 +414,6 @@ If `_index` and/or `_type` are supplied via options (or lib config), the will ap

`es.multiSearch(options, queries, callback)`

##### Percolate

Requires `_index` be specified either via lib config or via options when calling the operation.

`es.percolate(options, doc, callback)`

Requires `_index` be specified either via lib config or via options when calling the operation.
Also requires `_id`, but this must be specified via options.

`es.registerPercolator(options, query, callback)`

Requires `_index` be specified either via lib config or via options when calling the operation.
Also requires `_id`, but this must be specified via options.

`es.unregisterPercolator(options, callback)`

##### Search

Requires `_index` be specified either via lib config or via options when calling the operation.
Expand All @@ -446,9 +432,8 @@ var
},
es = elasticsearch(config);

// first search, specifying scan search_type
// first search
es.search({
search_type : 'scan',
scroll : '10m'
}, {
query : {
Expand Down Expand Up @@ -541,13 +526,6 @@ Requires `name`, but this must be specified via options.

`es.indices.deleteTemplate(options, callback)`

##### Delete Warmer

Requires `_index` be specified either via lib config or via options when calling the operation.
Also requires `name`, but this must be specified via options.

`es.indices.deleteWarmer(options, callback)`

##### Exists

Requires `_index` be specified either via lib config or via options when calling the operation.
Expand All @@ -568,22 +546,12 @@ Requires `_index` be specified either via lib config or via options when calling

`es.indices.openIndex(options, callback)`

##### Optimize

`es.indices.optimize(options, callback)`

##### Put Mapping

Requires `_index` and `_type` be specified either via lib config or via options when calling the operation.

`es.indices.putMapping(options, mapping, callback)`

##### Put Warmer

Requires `name`, but this must be specified via options.

`es.indices.putWarmer(options, warmer, callback)`

##### Refresh

`es.indices.refresh(options, callback)`
Expand All @@ -606,10 +574,6 @@ Requires `_index` be specified either via lib config or via options when calling

`es.indices.stats(options, callback)`

##### Status

`es.indices.status(options, callback`

##### Templates

Requires `name`, but this must be specified via options.
Expand All @@ -620,12 +584,6 @@ Requires `name`, but this must be specified via options.

`es.indices.updateSettings(options, settings, callback)`

##### Warmers

Requires `_index` be specified either via lib config or via options when calling the operation.

`es.indices.warmers(options, callback)`

### Cluster

All operations here interact with the Cluster portion of the Elasticsearch API.
Expand Down
81 changes: 0 additions & 81 deletions lib/core.js
Expand Up @@ -428,60 +428,6 @@ module.exports = function (config, req, self) {
return req.post(options, serializedQueries, callback);
};

// Redesigned in ES 1.0 - modifying for issue #38
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-percolate.html
self.percolate = function (options, doc, callback) {
if (!callback && typeof doc === 'function') {
callback = doc;
doc = options;
options = {};
}

var err = utils.optionsUndefined(options, config, ['_index', '_type']);
if (err) {
return callback(err);
}

var
index = utils.getIndexSyntax(options, config),
type = utils.getTypeSyntax(options, config);

options.query = utils.exclude(options, paramExcludes);

options.pathname = utils.pathAppend(index) +
utils.pathAppend(type) +
utils.pathAppend('_percolate');

// documentation indicates GET method...
// sending POST data via GET not typical, using POST instead
return req.post(options, doc, callback);
};

// Redesigned in ES 1.0 - modifying for issue #38
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-percolate.html
self.registerPercolator = function (options, query, callback) {
if (!callback && typeof query === 'function') {
callback = query;
query = options;
options = {};
}

var err = utils.optionsUndefined(options, config, ['_index', '_id']);
if (err) {
return callback(err);
}

var
index = utils.getIndexSyntax(options, config);

options.pathname =
utils.pathAppend(index) +
utils.pathAppend('.percolator') +
utils.pathAppend(options._id);

return req.put(options, query, callback);
};

// http://www.elasticsearch.org/guide/reference/api/search/
// .query to ease backwards compatibility
self.search = self.query = function (options, query, callback) {
Expand Down Expand Up @@ -512,7 +458,6 @@ module.exports = function (config, req, self) {
};

// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-scroll.html
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-search-type.html#scan
self.scroll = function (options, scrollId, callback) {
if (!callback && typeof scrollId === 'function') {
callback = scrollId;
Expand Down Expand Up @@ -555,32 +500,6 @@ module.exports = function (config, req, self) {
return req.post(options, query, callback);
};

// Redesigned in ES 1.0 - modifying for issue #38
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-percolate.html
self.unregisterPercolator = function (options, callback) {
if (!callback && typeof options === 'function') {
callback = options;
options = {};
}

var err = utils.optionsUndefined(options, config, ['_index', '_id']);
if (err) {
return callback(err);
}

var
index = utils.getIndexSyntax(options, config);

options.query = utils.exclude(options, paramExcludes);

options.pathname =
utils.pathAppend(index) +
utils.pathAppend('.percolator') +
utils.pathAppend(options._id);

return req.delete(options, callback);
};

// http://www.elasticsearch.org/guide/reference/api/update/
self.update = function (options, doc, callback) {
if (!callback && typeof doc === 'function') {
Expand Down
100 changes: 4 additions & 96 deletions lib/indices.js
Expand Up @@ -134,11 +134,7 @@ module.exports = function (config, req, self) {

options.pathname = utils.pathAppend(index);

if (data && data.mappings) {
return req.post(options, data, callback);
} else {
return req.put(options, data, callback);
}
return req.put(options, data, callback);
};

// http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/
Expand Down Expand Up @@ -240,29 +236,8 @@ module.exports = function (config, req, self) {
return req.delete(options, callback);
};

// http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/
self.deleteWarmer = function (options, callback) {
if (!callback && typeof options === 'function') {
callback = options;
options = {};
}

var err = utils.optionsUndefined(options, config, ['_index', 'name']);
if (err) {
return callback(err);
}

var index = utils.getIndexSyntax(options, config);

options.pathname = utils.pathAppend(index) +
utils.pathAppend('_warmer') +
utils.pathAppend(options.name);

return req.delete(options, callback);
};

// http://www.elasticsearch.org/guide/reference/api/admin-indices-indices-exists/
// http://www.elasticsearch.org/guide/reference/api/admin-indices-types-exists/
// https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-exists.html
// https://www.elastic.co/guide/en/elasticsearch/reference/5.5/indices-types-exists.html
// Also replicated (somewhat) in core... core.exists is more flexible, however
self.exists = function (options, callback) {
if (!callback && typeof options === 'function') {
Expand All @@ -279,8 +254,7 @@ module.exports = function (config, req, self) {
index = utils.getIndexSyntax(options, config),
type = utils.getTypeSyntax(options, config);

options.pathname = utils.pathAppend(index) +
utils.pathAppend(type);
options.pathname = type ? (utils.pathAppend(index) + '/_mapping' + utils.pathAppend(type)) : utils.pathAppend(index);

return req.head(options, function (err, data) {
if (err) {
Expand All @@ -292,7 +266,6 @@ module.exports = function (config, req, self) {

return callback(null, data);
}

return callback(err);
}

Expand Down Expand Up @@ -359,23 +332,6 @@ module.exports = function (config, req, self) {
return req.post(options, callback);
};

// http://www.elasticsearch.org/guide/reference/api/admin-indices-optimize/
self.optimize = function (options, callback) {
if (!callback && typeof options === 'function') {
callback = options;
options = {};
}

var index = utils.getIndexSyntax(options, config);

options.query = utils.exclude(options, paramExcludes);

options.pathname = utils.pathAppend(index) +
utils.pathAppend('_optimize');

return req.post(options, callback);
};

// http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping/
self.putMapping = function (options, mapping, callback) {
if (!callback && typeof mapping === 'function') {
Expand All @@ -402,31 +358,6 @@ module.exports = function (config, req, self) {
return req.put(options, mapping, callback);
};

// http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/
self.putWarmer = function (options, warmer, callback) {
if (!callback && typeof warmer === 'function') {
callback = warmer;
warmer = options;
options = {};
}

var err = utils.optionsUndefined(options, config, ['name']);
if (err) {
return callback(err);
}

var
index = utils.getIndexSyntax(options, config),
type = utils.getTypeSyntax(options, config);

options.pathname = utils.pathAppend(index) +
utils.pathAppend(type) +
utils.pathAppend('_warmer') +
utils.pathAppend(options.name);

return req.put(options, warmer, callback);
};

// http://www.elasticsearch.org/guide/reference/api/admin-indices-refresh/
self.refresh = function (options, callback) {
if (!callback && typeof options === 'function') {
Expand Down Expand Up @@ -573,28 +504,5 @@ module.exports = function (config, req, self) {
return req.put(options, settings, callback);
};

// http://www.elasticsearch.org/guide/reference/api/admin-indices-warmers/
self.warmers = function (options, callback) {
if (!callback && typeof options === 'function') {
callback = options;
options = {};
}

var err = utils.optionsUndefined(options, config, ['_index']);
if (err) {
return callback(err);
}

var index = utils.getIndexSyntax(options, config);

options.query = utils.exclude(options, paramExcludes.concat('name'));

options.pathname = utils.pathAppend(index) +
utils.pathAppend('_warmer') +
utils.pathAppend(options.name);

return req.get(options, callback);
};

return thenifyAll.withCallback(self, {});
};
6 changes: 6 additions & 0 deletions lib/utils.js
Expand Up @@ -48,6 +48,12 @@ exports.getFieldSyntax = function (options) {
syntax = options.field;
}

if (options.stored_fields && Array.isArray(options.stored_fields)) {
syntax = options.stored_fields.join(',');
} else if (options.store_field) {
syntax = options.store_field;
}

return syntax;
};

Expand Down

0 comments on commit 2eb92e1

Please sign in to comment.