Skip to content

Commit

Permalink
Merge pull request #33 from shelfio/feature/update-es-version-to-8.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
terret authored Sep 20, 2022
2 parents c572e9b + 78b4856 commit f459c2e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 29 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# 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: {}}})`
- Run Elasticsearch >= `v8.0.0` locally requires java `v17`/`v18`. See [Support Matrix](https://www.elastic.co/support/matrix#matrix_jvm)

## 4.0.0

- Upgrade `jest` to version 28
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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.x
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
Expand All @@ -100,12 +100,14 @@ $ 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
> Note: If you need to run elastic <= `v7.17.x` locally, then perform the steps above but for the java version 1.8.xxx
</details>
Expand Down
2 changes: 1 addition & 1 deletion jest-es-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@
"preset": "./jest-preset.js"
},
"dependencies": {
"@shelf/elasticsearch-local": "3.0.0",
"@shelf/elasticsearch-local": "3.2.0",
"cwd": "0.10.0"
},
"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",
Expand Down
13 changes: 3 additions & 10 deletions tests/elasticsearch.ts
Original file line number Diff line number Diff line change
@@ -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<ApiResponse> {
export function search(options: EsTypes.SearchRequest): Promise<EsTypes.SearchResponse> {
const es = getClient();

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return es.search(options);
}

export async function refreshAllIndexes(): Promise<TransportRequestPromise<ApiResponse>> {
export async function refreshAllIndexes(): Promise<EsTypes.IndicesRefreshResponse> {
const es = getClient();

return es.indices.refresh({index: '_all'});
Expand Down
13 changes: 6 additions & 7 deletions tests/search-by-term.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -12,7 +13,7 @@ export default async function getDocuments({
}: {
index: string;
id: string;
startFrom: number;
startFrom?: number;
}): Promise<GetDocumentsResponse> {
const body = {
_source: {
Expand All @@ -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};
}

0 comments on commit f459c2e

Please sign in to comment.