Skip to content

Commit 4b3c6f0

Browse files
refactor: migrate from Elasticsearch 6.8 to 9.2 and Node 18 to 24
- Upgrade @elastic/elasticsearch to ^9.0.0 - Upgrade Node.js engine requirement to >=24 - Refactor dumpOpenData.js and dumpUser.js for v9 client: - Remove body wrapper from responses - Update hits.total access to hits.total.value - Add track_total_hits: true for accurate counts - Update scrollId in each iteration for robustness - Update docker-compose.yml and CI/CD workflows: - Use Elasticsearch 9.2.2 image - Add discovery.type=single-node - Update Node.js to 24 - Update container lookup in opendata workflow - Update package-lock.json to reflect new dependency tree Co-authored-by: MrOrz <108608+MrOrz@users.noreply.github.com>
1 parent 38f5838 commit 4b3c6f0

7 files changed

Lines changed: 319 additions & 122 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ jobs:
1212
runs-on: ubuntu-latest
1313
services:
1414
rumors-test-db:
15-
image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.3.2
15+
image: docker.elastic.co/elasticsearch/elasticsearch:9.2.2
1616
ports:
1717
- 62223:9200
18+
env:
19+
discovery.type: single-node
1820
steps:
1921

2022
- name: Checkout rumors-db
@@ -23,7 +25,7 @@ jobs:
2325
repository: 'cofacts/rumors-db'
2426
- uses: actions/setup-node@v4
2527
with:
26-
node-version: '18'
28+
node-version: '24'
2729
cache: 'npm'
2830
- run: npm ci
2931
- name: Initialize DB indexes

.github/workflows/opendata.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
snapshot: ${{ steps.find-snapshot.outputs.snapshot }}
1313
services:
1414
elasticsearch:
15-
image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.3.2
15+
image: docker.elastic.co/elasticsearch/elasticsearch:9.2.2
1616
ports:
1717
- 62223:9200
1818
env:
@@ -29,7 +29,7 @@ jobs:
2929
- name: Setup Node.js
3030
uses: actions/setup-node@v4
3131
with:
32-
node-version: '18'
32+
node-version: '24'
3333
cache: 'npm'
3434

3535
- name: Prepare directory and secrets
@@ -43,7 +43,7 @@ jobs:
4343
- name: Install GCS Plugin & Keystore
4444
run: |
4545
# Find the container ID
46-
CONTAINER_ID=$(docker ps --filter "ancestor=docker.elastic.co/elasticsearch/elasticsearch-oss:6.3.2" --format "{{.ID}}")
46+
CONTAINER_ID=$(docker ps --filter "ancestor=docker.elastic.co/elasticsearch/elasticsearch:9.2.2" --format "{{.ID}}")
4747
echo "Elasticsearch container ID: $CONTAINER_ID"
4848
4949
if [ -z "$CONTAINER_ID" ]; then

docker-compose.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@ version: '2'
1111

1212
services:
1313
elasticsearch:
14-
image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.3.2
14+
image: docker.elastic.co/elasticsearch/elasticsearch:9.2.2
1515
volumes:
1616
- "./esdata:/usr/share/elasticsearch/data"
1717
environment:
1818
- "path.repo=/usr/share/elasticsearch/data"
19+
- "discovery.type=single-node"
1920
ports:
2021
- "62223:9200"
2122

2223
kibana:
23-
image: docker.elastic.co/kibana/kibana-oss:6.3.2
24+
image: docker.elastic.co/kibana/kibana:9.2.2
2425
ports:
2526
- "62224:5601"

dumpOpenData.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,27 @@ function sha256(input) {
2929
async function* scanIndex(index) {
3030
let processedCount = 0;
3131

32-
const { body: initialResult } = await client.search({
32+
let initialResult = await client.search({
3333
index,
3434
size: 200,
3535
scroll: '5m',
36+
track_total_hits: true,
3637
});
3738

38-
const totalCount = initialResult.hits.total;
39+
const totalCount = initialResult.hits.total.value;
40+
let scrollId = initialResult._scroll_id;
3941

4042
for (const hit of initialResult.hits.hits) {
4143
processedCount += 1;
4244
yield hit;
4345
}
4446

4547
while (processedCount < totalCount) {
46-
const { body: scrollResult } = await client.scroll({
47-
scrollId: initialResult._scroll_id,
48+
const scrollResult = await client.scroll({
49+
scrollId,
4850
scroll: '5m',
4951
});
52+
scrollId = scrollResult._scroll_id;
5053
for (const hit of scrollResult.hits.hits) {
5154
processedCount += 1;
5255
yield hit;

dumpUser.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,26 @@ function sha256(input) {
3939
async function scanIndex(index) {
4040
let result = [];
4141

42-
const { body: initialResult } = await client.search({
42+
const initialResult = await client.search({
4343
index,
4444
size: 200,
4545
scroll: '5m',
46+
track_total_hits: true,
4647
});
4748

48-
const totalCount = initialResult.hits.total;
49+
const totalCount = initialResult.hits.total.value;
50+
let scrollId = initialResult._scroll_id;
4951

5052
initialResult.hits.hits.forEach((hit) => {
5153
result.push(hit);
5254
});
5355

5456
while (result.length < totalCount) {
55-
const { body: scrollResult } = await client.scroll({
56-
scrollId: initialResult._scroll_id,
57+
const scrollResult = await client.scroll({
58+
scrollId,
5759
scroll: '5m',
5860
});
61+
scrollId = scrollResult._scroll_id;
5962
scrollResult.hits.hits.forEach((hit) => {
6063
result.push(hit);
6164
});

0 commit comments

Comments
 (0)