i have written a script that will create a key "source" on 4 indices of elasticsearch based on some condition . All of my 4 indices contain at least 2~3 million data . when i ran the script it added the key for only 3 entities , then i ran it again for the last entity (deals) exclusively. At last i noticed that some significant amount of docs were not having the new key which i introduced while running script . I can confirm that the conditions written in the script were correct . Here is the script code given below
const path = require('path');
require('dotenv').config({
path: path.resolve(__dirname, '../.env')
});
const client = require('../server/utils/es-utils').initializeESConnection();
(async function addField(){
const sq = {
script: {
source: `
if (ctx._source.sourceCreated != null) {
if (ctx._source.sourceCreated.recordSource != null) {
ctx._source.sourceCreated.source = ctx._source.sourceCreated.recordSource;
} else if (ctx._source.sourceCreated.clientType != null) {
ctx._source.sourceCreated.source = ctx._source.sourceCreated.clientType.toLowerCase();
}
}
`,
lang: "painless"
}
};
const indices = ['contacts','accounts','deals','crm-activities'];
for (const index of indices) {
const response = await client.updateByQuery({
index: index,
body: sq,
wait_for_completion: false,
refresh: true
});
console.log(`Updating documents in index ${index}`);
}
})()
I need to make sure that after running the script , i shall be able to see the key "source" on all of my docs of the given 4 indices