From e8b9118e70a249caa75480747fa096022383c26f Mon Sep 17 00:00:00 2001 From: Andrii Petlovanyi Date: Mon, 19 Sep 2022 21:04:13 +0300 Subject: [PATCH 1/8] feat: update ES version to 8.4.0 --- package.json | 2 +- tests/elasticsearch.ts | 13 +++---------- tests/search-by-term.test.ts | 30 +++++++++++++++--------------- tests/search-by-term.ts | 13 ++++++------- 4 files changed, 25 insertions(+), 33 deletions(-) diff --git a/package.json b/package.json index a2cd483..2d6c22d 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "devDependencies": { "@babel/cli": "7.18.9", "@babel/core": "7.18.9", - "@elastic/elasticsearch": "7.15.0", + "@elastic/elasticsearch": "8.4.0", "@shelf/babel-config": "1.2.0", "@shelf/eslint-config": "0.19.0", "@shelf/prettier-config": "0.0.7", diff --git a/tests/elasticsearch.ts b/tests/elasticsearch.ts index 0e8416f..41d7ae3 100644 --- a/tests/elasticsearch.ts +++ b/tests/elasticsearch.ts @@ -1,21 +1,14 @@ -import {Client} from '@elastic/elasticsearch'; -import { - ApiResponse, - TransportRequestOptions, - TransportRequestPromise -} from '@elastic/elasticsearch/lib/Transport'; +import {Client, estypes as EsTypes} from '@elastic/elasticsearch'; let client: undefined | Client; -export function search(options: TransportRequestOptions): TransportRequestPromise { +export function search(options: EsTypes.SearchRequest): Promise { const es = getClient(); - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore return es.search(options); } -export async function refreshAllIndexes(): Promise> { +export async function refreshAllIndexes(): Promise { const es = getClient(); return es.indices.refresh({index: '_all'}); diff --git a/tests/search-by-term.test.ts b/tests/search-by-term.test.ts index 9995cbf..88c50ef 100644 --- a/tests/search-by-term.test.ts +++ b/tests/search-by-term.test.ts @@ -14,22 +14,22 @@ describe('getDocuments', () => { }); expect(docs).toEqual({ - items: [ - { - _id: 'some-doc-id-1', - _index: 'documents', - _routing: 'some-doc-id-1', - _score: expect.any(Number), - _source: { - id: 'some-doc-id-1', - name: 'some-name-1' + _shards: {failed: 0, skipped: 0, successful: 1, total: 1}, + hits: { + hits: [ + { + _id: 'some-doc-id-1', + _index: 'documents', + _routing: 'some-doc-id-1', + _score: expect.any(Number), + _source: {id: 'some-doc-id-1', name: 'some-name-1'} } - } - ], - totalCount: { - relation: 'eq', - value: 1 - } + ], + max_score: expect.any(Number), + total: {relation: 'eq', value: 1} + }, + timed_out: false, + took: expect.any(Number) }); }); }); diff --git a/tests/search-by-term.ts b/tests/search-by-term.ts index 4930b65..b7de4e2 100644 --- a/tests/search-by-term.ts +++ b/tests/search-by-term.ts @@ -1,8 +1,9 @@ +import {estypes as EsTypes} from '@elastic/elasticsearch'; import {search} from './elasticsearch'; type GetDocumentsResponse = { - items: Array<{[key: string]: string}>; - totalCount: number; + items: EsTypes.SearchHit[]; + totalCount: EsTypes.SearchHitsMetadata['total']; }; export default async function getDocuments({ @@ -12,7 +13,7 @@ export default async function getDocuments({ }: { index: string; id: string; - startFrom: number; + startFrom?: number; }): Promise { const body = { _source: { @@ -28,10 +29,8 @@ export default async function getDocuments({ }; const { - body: { - hits: {hits, total} - } - } = await search({index, body}); + hits: {hits, total} + } = await search({index, ...body}); return {items: hits, totalCount: total}; } From 9a878aeb113c615d58e2988cad588ebe796fbfb7 Mon Sep 17 00:00:00 2001 From: Andrii Petlovanyi Date: Mon, 19 Sep 2022 21:04:52 +0300 Subject: [PATCH 2/8] chore: bump @shelf/elasticsearch-local version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2d6c22d..ff7e48a 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "preset": "./jest-preset.js" }, "dependencies": { - "@shelf/elasticsearch-local": "3.0.0", + "@shelf/elasticsearch-local": "3.2.0", "cwd": "0.10.0" }, "devDependencies": { From 821ab0deae06db7eb2191e543a3f0be93e669b73 Mon Sep 17 00:00:00 2001 From: Andrii Petlovanyi Date: Mon, 19 Sep 2022 21:09:52 +0300 Subject: [PATCH 3/8] docs: add a description of changes coming from v5.0.0 --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8e0494..80ac354 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Breaking Changes +## 5.0.0 + +- Upgrade `@elastic/elasticsearch` to version 8.4.0 + - Changed `getDocuments` request parameters according to the new Elasticsearch version + - use `getDocuments({index, {query: {}})` instead of `getDocuments({index, body: {query: {}}})` + ## 4.0.0 - Upgrade `jest` to version 28 From b9b081f4c127183747223b02a25257e8febfe919 Mon Sep 17 00:00:00 2001 From: Andrii Petlovanyi Date: Mon, 19 Sep 2022 21:11:37 +0300 Subject: [PATCH 4/8] refactor: rollback tests changes --- tests/search-by-term.test.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/search-by-term.test.ts b/tests/search-by-term.test.ts index 88c50ef..9995cbf 100644 --- a/tests/search-by-term.test.ts +++ b/tests/search-by-term.test.ts @@ -14,22 +14,22 @@ describe('getDocuments', () => { }); expect(docs).toEqual({ - _shards: {failed: 0, skipped: 0, successful: 1, total: 1}, - hits: { - hits: [ - { - _id: 'some-doc-id-1', - _index: 'documents', - _routing: 'some-doc-id-1', - _score: expect.any(Number), - _source: {id: 'some-doc-id-1', name: 'some-name-1'} + items: [ + { + _id: 'some-doc-id-1', + _index: 'documents', + _routing: 'some-doc-id-1', + _score: expect.any(Number), + _source: { + id: 'some-doc-id-1', + name: 'some-name-1' } - ], - max_score: expect.any(Number), - total: {relation: 'eq', value: 1} - }, - timed_out: false, - took: expect.any(Number) + } + ], + totalCount: { + relation: 'eq', + value: 1 + } }); }); }); From 2fb2d413331e73073b501d46e61b9fe641228fa0 Mon Sep 17 00:00:00 2001 From: Andrii Petlovanyi Date: Tue, 20 Sep 2022 17:12:19 +0300 Subject: [PATCH 5/8] feat: update README.md according to the new java version --- README.md | 19 +++++++++---------- jest-es-config.js | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index ff8cd1f..5b6bd1b 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ If you have a custom `jest.config.js` make sure you remove `testEnvironment` pro ```js module.exports = () => { return { - esVersion: '7.6.0', // ! must be exact version. Ref: https://github.com/elastic/elasticsearch-js . + esVersion: '8.4.0', // ! must be exact version. Ref: https://github.com/elastic/elasticsearch-js . // don't be shy to fork our code and update deps to correct. clusterName: 'your-cluster-name', nodeName: 'your-node-name', @@ -84,14 +84,14 @@ The main reason why this issue appears is that you have an incompatible java ver $ /usr/libexec/java_home -V ``` -2. If you see version 1.8.xxx +2. If you see version 18.0.xxx Add this command to your bashrc, zshrc, etc ```shell -$ /usr/libexec/java_home -v 1.8 +$ /usr/libexec/java_home -v 18 ``` -3. If you see no versions or do not have a compatible version installed - Install version 1.8xxx -https://www.java.com/en/download/ +3. If you see no versions or do not have a compatible version installed - Install version 18 +https://www.oracle.com/java/technologies/downloads/#java18 4. Reload the console and check the java version with ```shell @@ -99,13 +99,12 @@ $ java -version ``` Output for proper work ```shell -$ java -version -java version "1.8.0_333" -Java(TM) SE Runtime Environment (build 1.8.0_333-b02) -Java HotSpot(TM) 64-Bit Server VM (build 25.333-b02, mixed mode) +java version "18.0.2.1" +Java(TM) SE Runtime Environment (build 18.0.2.1+1-1) +Java HotSpot(TM) 64-Bit Server VM (build 18.0.2.1+1-1, mixed mode, sharing) ``` -5. Go to step 2 and set version 1.8xx as a default for the shell +5. Go to step **2** and set version 18.xx as a default for the shell diff --git a/jest-es-config.js b/jest-es-config.js index c345c0a..ea65437 100644 --- a/jest-es-config.js +++ b/jest-es-config.js @@ -2,7 +2,7 @@ const documentsMapping = require('./index-mapping'); module.exports = function getClusterSetting() { return { - esVersion: '8.2.0', + esVersion: '8.4.0', clusterName: 'docs', nodeName: 'docs', port: 9200, From d253e38eb0643e668cb375c7f7d5dec8f1ce5b70 Mon Sep 17 00:00:00 2001 From: Andrii Petlovanyi Date: Tue, 20 Sep 2022 17:17:24 +0300 Subject: [PATCH 6/8] feat: add note for the elactic version <=7.17.x in README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5b6bd1b..cc2b9de 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ The main reason why this issue appears is that you have an incompatible java ver $ /usr/libexec/java_home -V ``` -2. If you see version 18.0.xxx +2. If you see version 18.0.x Add this command to your bashrc, zshrc, etc ```shell $ /usr/libexec/java_home -v 18 @@ -106,6 +106,8 @@ Java HotSpot(TM) 64-Bit Server VM (build 18.0.2.1+1-1, mixed mode, sharing) 5. Go to step **2** and set version 18.xx as a default for the shell +> Note: If you need to run elastic <= `v7.17.x` locally, then perform the steps above but for the java version 1.8.xxx + From 893aece661ec5a433a5f1b7cfac210cb2406b87e Mon Sep 17 00:00:00 2001 From: Andrii Petlovanyi Date: Tue, 20 Sep 2022 17:22:18 +0300 Subject: [PATCH 7/8] feat: update CHANGELOG.md according to the new java version --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80ac354..3389d1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Upgrade `@elastic/elasticsearch` to version 8.4.0 - Changed `getDocuments` request parameters according to the new Elasticsearch version - use `getDocuments({index, {query: {}})` instead of `getDocuments({index, body: {query: {}}})` + - Run Elasticsearch >= `v8.0.0` locally requires java `v17`/`v18`. See [Support Matrix](https://www.elastic.co/support/matrix#matrix_jvm) ## 4.0.0 From 78b4856d1930e87022a9a74b9ff006c2af628bd0 Mon Sep 17 00:00:00 2001 From: Andrii Petlovanyi Date: Tue, 20 Sep 2022 17:24:19 +0300 Subject: [PATCH 8/8] refactor: add 'java -version' command to the README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index cc2b9de..0bc7c02 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,7 @@ $ java -version ``` Output for proper work ```shell +$ java -version java version "18.0.2.1" Java(TM) SE Runtime Environment (build 18.0.2.1+1-1) Java HotSpot(TM) 64-Bit Server VM (build 18.0.2.1+1-1, mixed mode, sharing)