Skip to content

Commit 687043a

Browse files
jciolekdaffl
authored andcommitted
Drop support for elasticsearch 2.4 (#91)
1 parent 1c01024 commit 687043a

File tree

21 files changed

+148
-120
lines changed

21 files changed

+148
-120
lines changed

.istanbul.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

.nycrc.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
all: false
2+
exclude:
3+
- test/**/*
4+
- test-utils/**/*
5+
reporter:
6+
- html
7+
- text
8+
- lcov
9+
watermarks:
10+
statements: [50, 80]
11+
lines: [50, 80]
12+
functions: [50, 80]
13+
branches: [50, 80]

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ node_js: node
55
services:
66
- docker
77
env:
8-
- ES_VERSION=2.4.3
8+
- ES_VERSION=5.0.2
99
- ES_VERSION=5.6.7
1010
- ES_VERSION=6.6.2
1111
- ES_VERSION=6.7.2

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The following options can be passed when creating a new Elasticsearch service:
4343
- `Model` (**required**) - The Elasticsearch client instance.
4444
- `elasticsearch` (**required**) - Configuration object for elasticsearch requests. The required properties are `index` and `type`. Apart from that you can specify anything that should be passed to **all** requests going to Elasticsearch. Another recognised property is [`refresh`](https://www.elastic.co/guide/en/elasticsearch/guide/2.x/near-real-time.html#refresh-api) which is set to `false` by default. Anything else use at your own risk.
4545
- `paginate` [optional] - A pagination object containing a `default` and `max` page size (see the [Pagination documentation](https://docs.feathersjs.com/api/databases/common.html#pagination)).
46-
- `esVersion` (default: '2.4') [optional] - A string indicating which version of Elasticsearch the service is supposed to be talking to. Based on this setting the service will choose compatible API. If you plan on using Elasticsearch 6.0+ features (e.g. join fields) it's quite important to have it set, as there were breaking changes in Elasticsearch 6.0.
46+
- `esVersion` (default: '5.0') [optional] - A string indicating which version of Elasticsearch the service is supposed to be talking to. Based on this setting the service will choose compatible API. If you plan on using Elasticsearch 6.0+ features (e.g. join fields) it's quite important to have it set, as there were breaking changes in Elasticsearch 6.0.
4747
- `id` (default: '_id') [optional] - The id property of your documents in this service.
4848
- `parent` (default: '_parent') [optional] - The parent property, which is used to pass document's parent id.
4949
- `routing` (default: '_routing') [optional] - The routing property, which is used to pass document's routing parameter.
@@ -397,7 +397,7 @@ docService.remove(
397397

398398
## Supported Elasticsearch versions
399399

400-
feathers-elasticsearch is currently tested on Elasticsearch 2.4, 5.6, 6.6, 6.7, 6.8, 7.0 and 7.1 Please note, even though the lowest version supported is 2.4, that does not mean it wouldn't work fine on anything lower than 2.4.
400+
feathers-elasticsearch is currently tested on Elasticsearch 5.0, 5.6, 6.6, 6.7, 6.8, 7.0 and 7.1 Please note, we have recently dropped support for version 2.4, as its life ended quite a while back. If you are still running Elasticsearch 2.4 and want to take advantage of feathers-elasticsearch, please use version 2.x of this package.
401401

402402
## Quirks
403403

@@ -424,7 +424,7 @@ Currently feathers-elasticsearch supports most important full-text queries in th
424424

425425
### Performance considerations
426426

427-
None of the data mutating operations in Elasticsearch v2.4 (create, update, patch, remove) returns the full resulting document, therefore I had to resolve to using get as well in order to return complete data. This solution is of course adding a bit of an overhead, although it is also compliant with the standard behaviour expected of a feathers database adapter.
427+
Most of the data mutating operations in Elasticsearch v5.0 (create, update, remove) do not return the full resulting document, therefore I had to resolve to using get as well in order to return complete data. This solution is of course adding a bit of an overhead, although it is also compliant with the standard behaviour expected of a feathers database adapter.
428428

429429
The conceptual solution for that is quite simple. This behaviour will be configurable through a `lean` switch allowing to get rid of those additional gets should they be not needed for your application. This feature will be added soon as well.
430430

File renamed without changes.
File renamed without changes.

lib/core/get.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
'use strict';
22

33
const { NotFound } = require('@feathersjs/errors');
4-
const { mapGet, getDocDescriptor, removeProps } = require('../utils');
4+
const { mapGet, getDocDescriptor, getQueryLength } = require('../utils');
55

66
function get (service, id, params) {
77
let { filters, query } = service.filterQuery(params);
8-
let queryLength = Object.keys(
9-
removeProps(query, service.routing, service.parent)
10-
).length;
8+
let queryLength = getQueryLength(service, query);
119

1210
if (queryLength >= 1) {
1311
return service.core.find(

lib/core/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ function getCore (esVersion) {
88
get: require('./get'),
99
getBulk: require('./get-bulk'),
1010
create: require(
11-
`./create/${getCompatVersion(['2.4', '6.0'], esVersion)}`
11+
`./create/${getCompatVersion(['5.0', '6.0'], esVersion)}`
1212
),
1313
createBulk: require(
14-
`./create-bulk/${getCompatVersion(['2.4', '6.0'], esVersion)}`
14+
`./create-bulk/${getCompatVersion(['5.0', '6.0'], esVersion)}`
1515
),
1616
patch: require('./patch'),
1717
patchBulk: require('./patch-bulk'),
1818
remove: require('./remove'),
1919
removeBulk: require('./remove-bulk'),
2020
update: require(
21-
`./update/${getCompatVersion(['2.4', '6.0'], esVersion)}`
21+
`./update/${getCompatVersion(['5.0', '6.0'], esVersion)}`
2222
),
2323
raw: require('./raw')
2424
};

lib/core/patch-bulk.js

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
const { mapBulk, removeProps, getDocDescriptor } = require('../utils');
44

55
function patchBulk (service, data, params) {
6-
const { find, getBulk } = service.core;
6+
const { find } = service.core;
7+
const { filters } = service.filterQuery(params);
8+
79
// Poor man's semi-deep object extension. We only want to override params.query.$select here.
810
let findParams = Object.assign(
911
removeProps(params, 'query'),
@@ -31,7 +33,7 @@ function patchBulk (service, data, params) {
3133

3234
bulkUpdateParams = Object.assign(
3335
{
34-
_source: false,
36+
_source: filters.$select,
3537
body: found.reduce((result, item) => {
3638
let { _id, _parent: parent, _routing: routing } = item[service.meta];
3739
let { doc } = getDocDescriptor(service, data);
@@ -46,40 +48,9 @@ function patchBulk (service, data, params) {
4648
);
4749

4850
return service.Model.bulk(bulkUpdateParams)
49-
.then(result => {
50-
let patched = mapBulk(result.items, service.id, service.meta, service.join);
51-
let docs = patched
52-
.map((item, index) => Object.assign(
53-
{ [service.routing]: bulkUpdateParams.body[index * 2].update.routing },
54-
item
55-
))
56-
.filter(item => item[service.meta].status === 200)
57-
.map(item => ({
58-
_id: item[service.meta]._id,
59-
routing: item[service.routing]
60-
}));
61-
62-
if (!docs.length) {
63-
return patched;
64-
}
65-
66-
return getBulk(service, docs, params)
67-
.then(fetched => {
68-
let fetchedIndex = 0;
69-
70-
return patched.map(patchedItem => {
71-
if (patchedItem[service.meta].status === 200) {
72-
let fetchedItem = fetched[fetchedIndex];
73-
74-
fetchedIndex += 1;
75-
76-
return fetchedItem;
77-
}
78-
79-
return patchedItem;
80-
});
81-
});
82-
});
51+
.then(result =>
52+
mapBulk(result.items, service.id, service.meta, service.join)
53+
);
8354
});
8455
}
8556

lib/core/patch.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
'use strict';
22

3-
const { getDocDescriptor } = require('../utils');
3+
const { getDocDescriptor, getQueryLength, mapPatch } = require('../utils');
44

55
function patch (service, id, data, params) {
66
const { get } = service.core;
7-
let { query } = service.filterQuery(params);
7+
let { filters, query } = service.filterQuery(params);
88
let { routing } = getDocDescriptor(service, query);
99
let { doc } = getDocDescriptor(service, data);
1010
let updateParams = Object.assign(
1111
{
1212
id: String(id),
1313
routing,
1414
body: { doc },
15-
_source: false
15+
_source: filters.$select
1616
},
1717
service.esParams
1818
);
1919

20-
return service.Model.update(updateParams)
21-
.then(() => get(service, id, params));
20+
const queryPromise = getQueryLength(service, query) >= 1
21+
? get(service, updateParams.id, params)
22+
: Promise.resolve();
23+
24+
return queryPromise
25+
.then(() => service.Model.update(updateParams))
26+
.then(result => mapPatch(result, service.id, service.meta, service.join));
2227
}
2328

2429
module.exports = patch;

0 commit comments

Comments
 (0)