-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcross-version-reindex.js
More file actions
77 lines (69 loc) · 1.92 KB
/
cross-version-reindex.js
File metadata and controls
77 lines (69 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* Cross-Version Reindex Example
*
* Demonstrates reindexing from Elasticsearch 8.x to 9.x.
* The library automatically detects the ES version and uses the appropriate client.
*/
const transformer = require('node-es-transformer');
const logger = require('./_logger');
// Example 1: Auto-detection (recommended)
transformer({
sourceClientConfig: {
node: 'https://es8-cluster.example.com:9200',
auth: {
apiKey: process.env.ES8_API_KEY,
},
},
targetClientConfig: {
node: 'https://es9-cluster.example.com:9200',
auth: {
apiKey: process.env.ES9_API_KEY,
},
},
sourceIndexName: 'my-index-v1',
targetIndexName: 'my-index-v1',
// Optional: Transform data during migration
transform(doc) {
// Clean up deprecated fields, add new fields, etc.
return {
...doc,
migrated_at: new Date().toISOString(),
};
},
})
.then(() => {
logger.info('Cross-version reindex complete');
})
.catch(err => {
logger.error({ err }, 'Error during cross-version reindex');
});
// Example 2: Using pre-instantiated clients (advanced)
/*
const { Client: Client8 } = require('es8');
const { Client: Client9 } = require('es9');
const sourceClient = new Client8({
node: 'https://es8-cluster.example.com:9200',
auth: { apiKey: process.env.ES8_API_KEY }
});
const targetClient = new Client9({
node: 'https://es9-cluster.example.com:9200',
auth: { apiKey: process.env.ES9_API_KEY }
});
transformer({
sourceClient,
targetClient,
sourceIndexName: 'my-index-v1',
targetIndexName: 'my-index-v1'
});
*/
// Example 3: Force specific client versions (if auto-detection fails)
/*
transformer({
sourceClientConfig: { node: 'https://es8.example.com:9200' },
targetClientConfig: { node: 'https://es9.example.com:9200' },
sourceClientVersion: 8, // Force ES 8.x client
targetClientVersion: 9, // Force ES 9.x client
sourceIndexName: 'my-index',
targetIndexName: 'my-index'
});
*/