Skip to content

Commit

Permalink
Drop support for elasticsearch 2.4 (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
jciolek authored and daffl committed Sep 5, 2019
1 parent 1c01024 commit 687043a
Show file tree
Hide file tree
Showing 21 changed files with 148 additions and 120 deletions.
15 changes: 0 additions & 15 deletions .istanbul.yml

This file was deleted.

13 changes: 13 additions & 0 deletions .nycrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
all: false
exclude:
- test/**/*
- test-utils/**/*
reporter:
- html
- text
- lcov
watermarks:
statements: [50, 80]
lines: [50, 80]
functions: [50, 80]
branches: [50, 80]
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ node_js: node
services:
- docker
env:
- ES_VERSION=2.4.3
- ES_VERSION=5.0.2
- ES_VERSION=5.6.7
- ES_VERSION=6.6.2
- ES_VERSION=6.7.2
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The following options can be passed when creating a new Elasticsearch service:
- `Model` (**required**) - The Elasticsearch client instance.
- `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.
- `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)).
- `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.
- `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.
- `id` (default: '_id') [optional] - The id property of your documents in this service.
- `parent` (default: '_parent') [optional] - The parent property, which is used to pass document's parent id.
- `routing` (default: '_routing') [optional] - The routing property, which is used to pass document's routing parameter.
Expand Down Expand Up @@ -397,7 +397,7 @@ docService.remove(

## Supported Elasticsearch versions

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.
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.

## Quirks

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

### Performance considerations

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.
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.

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.

Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 2 additions & 4 deletions lib/core/get.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
'use strict';

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

function get (service, id, params) {
let { filters, query } = service.filterQuery(params);
let queryLength = Object.keys(
removeProps(query, service.routing, service.parent)
).length;
let queryLength = getQueryLength(service, query);

if (queryLength >= 1) {
return service.core.find(
Expand Down
6 changes: 3 additions & 3 deletions lib/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ function getCore (esVersion) {
get: require('./get'),
getBulk: require('./get-bulk'),
create: require(
`./create/${getCompatVersion(['2.4', '6.0'], esVersion)}`
`./create/${getCompatVersion(['5.0', '6.0'], esVersion)}`
),
createBulk: require(
`./create-bulk/${getCompatVersion(['2.4', '6.0'], esVersion)}`
`./create-bulk/${getCompatVersion(['5.0', '6.0'], esVersion)}`
),
patch: require('./patch'),
patchBulk: require('./patch-bulk'),
remove: require('./remove'),
removeBulk: require('./remove-bulk'),
update: require(
`./update/${getCompatVersion(['2.4', '6.0'], esVersion)}`
`./update/${getCompatVersion(['5.0', '6.0'], esVersion)}`
),
raw: require('./raw')
};
Expand Down
43 changes: 7 additions & 36 deletions lib/core/patch-bulk.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
const { mapBulk, removeProps, getDocDescriptor } = require('../utils');

function patchBulk (service, data, params) {
const { find, getBulk } = service.core;
const { find } = service.core;
const { filters } = service.filterQuery(params);

// Poor man's semi-deep object extension. We only want to override params.query.$select here.
let findParams = Object.assign(
removeProps(params, 'query'),
Expand Down Expand Up @@ -31,7 +33,7 @@ function patchBulk (service, data, params) {

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

return service.Model.bulk(bulkUpdateParams)
.then(result => {
let patched = mapBulk(result.items, service.id, service.meta, service.join);
let docs = patched
.map((item, index) => Object.assign(
{ [service.routing]: bulkUpdateParams.body[index * 2].update.routing },
item
))
.filter(item => item[service.meta].status === 200)
.map(item => ({
_id: item[service.meta]._id,
routing: item[service.routing]
}));

if (!docs.length) {
return patched;
}

return getBulk(service, docs, params)
.then(fetched => {
let fetchedIndex = 0;

return patched.map(patchedItem => {
if (patchedItem[service.meta].status === 200) {
let fetchedItem = fetched[fetchedIndex];

fetchedIndex += 1;

return fetchedItem;
}

return patchedItem;
});
});
});
.then(result =>
mapBulk(result.items, service.id, service.meta, service.join)
);
});
}

Expand Down
15 changes: 10 additions & 5 deletions lib/core/patch.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
'use strict';

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

function patch (service, id, data, params) {
const { get } = service.core;
let { query } = service.filterQuery(params);
let { filters, query } = service.filterQuery(params);
let { routing } = getDocDescriptor(service, query);
let { doc } = getDocDescriptor(service, data);
let updateParams = Object.assign(
{
id: String(id),
routing,
body: { doc },
_source: false
_source: filters.$select
},
service.esParams
);

return service.Model.update(updateParams)
.then(() => get(service, id, params));
const queryPromise = getQueryLength(service, query) >= 1
? get(service, updateParams.id, params)
: Promise.resolve();

return queryPromise
.then(() => service.Model.update(updateParams))
.then(result => mapPatch(result, service.id, service.meta, service.join));
}

module.exports = patch;
File renamed without changes.
11 changes: 9 additions & 2 deletions lib/utils/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function getDocDescriptor (service, data, ...supplementaryData) {
function getCompatVersion (
allVersions,
curVersion,
defVersion = '2.4'
defVersion = '5.0'
) {
const curVersionNum = Number(curVersion);
const prevVersionsNum = allVersions
Expand All @@ -81,11 +81,18 @@ function getCompatProp (versionMap, curVersion) {
return versionMap[getCompatVersion(Object.keys(versionMap), curVersion)];
}

function getQueryLength (service, query) {
return Object.keys(
removeProps(query, service.routing, service.parent)
).length;
}

module.exports = {
getType,
validateType,
removeProps,
getDocDescriptor,
getCompatVersion,
getCompatProp
getCompatProp,
getQueryLength
};
4 changes: 3 additions & 1 deletion lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const {
removeProps,
getDocDescriptor,
getCompatVersion,
getCompatProp
getCompatProp,
getQueryLength
} = require('./core');

function mapFind (results, idProp, metaProp, joinProp, filters, hasPagination) {
Expand Down Expand Up @@ -82,6 +83,7 @@ module.exports = {
getDocDescriptor,
getCompatVersion,
getCompatProp,
getQueryLength,
parseQuery,
mapFind,
mapGet,
Expand Down
34 changes: 0 additions & 34 deletions test-utils/schema-2.4.js

This file was deleted.

11 changes: 7 additions & 4 deletions test-utils/test-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ const { getCompatVersion, getCompatProp } = require('../lib/utils/core');

let apiVersion = null;
let client = null;
let schemaVersions = ['2.4', '5.0', '6.0', '7.0'];
let schemaVersions = ['5.0', '6.0', '7.0'];

const compatVersion = getCompatVersion(schemaVersions, getApiVersion());
const compatSchema = require(`./schema-${compatVersion}`);

function getServiceConfig (serviceName) {
let configs = {
'2.4': {
'5.0': {
index: 'test',
type: serviceName
},
Expand All @@ -36,8 +36,11 @@ function getServiceConfig (serviceName) {

function getApiVersion () {
if (!apiVersion) {
const esVersion = process.env.ES_VERSION || '2.4.0';
apiVersion = esVersion.split('.').slice(0, 2).join('.');
const esVersion = process.env.ES_VERSION || '5.0.0';
const [major, minor] = esVersion.split('.').slice(0, 2);

// elasticsearch client 15.5 does not support api 5.0 - 5.5
apiVersion = (+major === 5 && +minor < 6) ? '5.6' : `${major}.${minor}`;
}

return apiVersion;
Expand Down
8 changes: 4 additions & 4 deletions test/core/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function find (app, serviceName, esVersion) {

it('can $all', () => {
const expectedLength = getCompatProp({
'2.4': 3,
'5.0': 3,
'6.0': 6
}, esVersion);

Expand Down Expand Up @@ -195,7 +195,7 @@ function find (app, serviceName, esVersion) {

it('can $child', () => {
const types = {
'2.4': 'aka',
'5.0': 'aka',
'6.0': 'alias'
};

Expand All @@ -218,7 +218,7 @@ function find (app, serviceName, esVersion) {

it('can $parent', () => {
const types = {
'2.4': 'people',
'5.0': 'people',
'6.0': 'real'
};

Expand Down Expand Up @@ -270,7 +270,7 @@ function find (app, serviceName, esVersion) {

it('can $missing', () => {
const expectedLength = getCompatProp({
'2.4': 2,
'5.0': 2,
'6.0': 5
}, esVersion);

Expand Down
Loading

0 comments on commit 687043a

Please sign in to comment.