Skip to content

Commit

Permalink
RA-25033: Added Index type field mapping to identify ridedetails and …
Browse files Browse the repository at this point in the history
…audit logs
  • Loading branch information
shubhisood committed Aug 12, 2020
1 parent e58feba commit dfd0f3a
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions reindexAuditLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ async function bulkIndexAuditLogs(rideId, auditLogs, rideRange) {
_id: value._id,
},
});
elindex.push(value._source);
const source = {...value._source, index_type: 'audit_log' }
elindex.push(source);
});
try {
await callBulkAPI(elindex);
Expand Down Expand Up @@ -65,9 +66,7 @@ async function reindexAuditLogs(rideRange) {
if(auditLogs && auditLogs.length) {
await bulkIndexAuditLogs(rideIndex, auditLogs, rideRange);
}
let scrollCount = 0;
while(scrollId && count > MAX_DOC_COUNT) {
console.error('scroll called', scrollCount++)
const { hits: { hits: auditLogs }, _scroll_id: newScrollId } = await elasticClient.scroll({scroll: '1m', scrollId});
scrollId = newScrollId;
if (auditLogs && auditLogs.length) {
Expand All @@ -76,7 +75,6 @@ async function reindexAuditLogs(rideRange) {
break;
}
}
console.error('Setting ride ID in redis', rideIndex)
redisClient.set(`elasticCleanUp:${rideRange.index}:rideId`, rideIndex);
}
}
Expand All @@ -98,7 +96,7 @@ async function createIndex(indexName, fromIndex) {
const result = await elasticClient.indices.getMapping({ index: fromIndex });
const { mappings } = result[fromIndex];
const properties = {};
properties.type = { type: 'keyword' };
properties.index_type = { type: 'keyword' };
Object.entries(mappings).forEach(([key, value]) => {
if (value.properties) {
Object.entries(value.properties).forEach(([propKey, propValue]) => {
Expand Down

0 comments on commit dfd0f3a

Please sign in to comment.