Skip to content

Commit

Permalink
Update elasticsearch package to be compatible with elasticsearch8
Browse files Browse the repository at this point in the history
The previous package was producing an error[^1]. Given that the old npm
package is deprecated[^2], I've switched to the new recommended client.

The new npm package has a peculiar (though well reasoned) versioning
scheme.

The major version of the new npm package denotes the minimum supported
elasticsearch server version.

The package is (apparently) given forward compatibility with newer
version. So in this case, using version 7, means we can talk to
elasticsearch7 and elasticsearch8 (but not elasticsearch6).

This does mean that breaking changes, like dropping node versions, can
occur in a minor release, hence the more restrictive versioning
constraint (~7.17.0 instead of ^7.17.0).

[1] fixes error:
```
--------------
 create index
--------------

/home/runner/work/schema/schema/node_modules/elasticsearch/src/lib/utils.js:303
      throw new TypeError(err);
      ^

TypeError: Invalid apiVersion "8.0", expected a function or one of
_default, 7.6, 7.5, 7.4, 7.3, 7.2, 7.1, 7.0, 6.8, 5.6, 7.7, 7.x, master
    at Object.utils.funcEnum
(/home/runner/work/schema/schema/node_modules/elasticsearch/src/lib/utils.js:303:13)
    at new Client
(/home/runner/work/schema/schema/node_modules/elasticsearch/src/lib/client.js:74:33)
    at Object.<anonymous>
(/home/runner/work/schema/schema/scripts/create_index.js:11:16)
    at Module._compile (node:internal/modules/cjs/loader:1196:14)
    at Object.Module._extensions..js
(node:internal/modules/cjs/loader:1250:10)
    at Module.load (node:internal/modules/cjs/loader:1074:32)
    at Function.Module._load (node:internal/modules/cjs/loader:909:12)
    at Function.executeUserEntryPoint [as runMain]
(node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:22:47
Error: Process completed with exit code 1.
```

[2] old package is deprecated
From https://www.npmjs.com/package/elasticsearch
> ⚠️ This client is no longer maintained. We strongly advise you to
migrate to the [new Elasticsearch
client](https://www.elastic.co/blog/new-elasticsearch-javascript-client-released).
  • Loading branch information
michaelkirk committed Jul 21, 2023
1 parent 78a95cf commit 110ac78
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"dependencies": {
"@hapi/joi": "^16.1.8",
"colors": "^1.1.2",
"elasticsearch": "^16.0.0",
"@elastic/elasticsearch": "~7.17.0",
"glob": "^7.1.6",
"lodash": "^4.17.15",
"pelias-config": "^4.5.0",
Expand Down
2 changes: 1 addition & 1 deletion scripts/check_plugins.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const colors = require('colors/safe');
const config = require('pelias-config').generate();
const es = require('elasticsearch');
const es = require('@elastic/elasticsearch');
const client = new es.Client(config.esclient);
const cli = require('./cli');

Expand Down
2 changes: 1 addition & 1 deletion scripts/check_version.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const _ = require('lodash');
const semver = require('semver');
const es = require('elasticsearch');
const es = require('@elastic/elasticsearch');
const config = require('pelias-config').generate();
const client = new es.Client(config.esclient);
const cli = require('./cli');
Expand Down
2 changes: 1 addition & 1 deletion scripts/create_index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const child_process = require('child_process');
const config = require('pelias-config').generate();
const es = require('elasticsearch');
const es = require('@elastic/elasticsearch');
const SUPPORTED_ES_VERSIONS = '>=7.4.2';

const cli = require('./cli');
Expand Down
2 changes: 1 addition & 1 deletion scripts/drop_index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const colors = require('colors/safe');
const config = require('pelias-config').generate();
const es = require('elasticsearch');
const es = require('@elastic/elasticsearch');
const client = new es.Client(config.esclient);
const readline = require('readline');
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
Expand Down
2 changes: 1 addition & 1 deletion scripts/info.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var config = require('pelias-config').generate().esclient;
var es = require('elasticsearch');
var es = require('@elastic/elasticsearch');
var client = new es.Client(config);

client.info( {}, console.log.bind(console) );
2 changes: 1 addition & 1 deletion scripts/update_settings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var config = require('pelias-config').generate();
var es = require('elasticsearch');
var es = require('@elastic/elasticsearch');
var client = new es.Client(config.esclient);
var schema = require('../schema');

Expand Down

0 comments on commit 110ac78

Please sign in to comment.