Skip to content

Commit

Permalink
[backend] Fix usage of ElasticSearch ID (#9727)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelHassine authored Jan 27, 2025
1 parent e277e6c commit 1948fa5
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions opencti-platform/opencti-graphql/src/database/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -4051,7 +4051,7 @@ export const elIndexElements = async (context, user, indexingType, elements) =>
const body = transformedElements.flatMap((elementDoc) => {
const doc = elementDoc;
return [
{ index: { _index: doc._index, _id: doc.internal_id, retry_on_conflict: ES_RETRY_ON_CONFLICT } },
{ index: { _index: doc._index, _id: doc._id ?? doc.internal_id, retry_on_conflict: ES_RETRY_ON_CONFLICT } },
R.pipe(R.dissoc('_index'))(doc),
];
});
Expand Down Expand Up @@ -4142,7 +4142,7 @@ export const elUpdateRelationConnections = async (elements) => {
const source = 'def conn = ctx._source.connections.find(c -> c.internal_id == params.id); '
+ 'for (change in params.changes.entrySet()) { conn[change.getKey()] = change.getValue() }';
const bodyUpdate = elements.flatMap((doc) => [
{ update: { _index: doc._index, _id: doc.id, retry_on_conflict: ES_RETRY_ON_CONFLICT } },
{ update: { _index: doc._index, _id: doc._id ?? doc.id, retry_on_conflict: ES_RETRY_ON_CONFLICT } },
{ script: { source, params: { id: doc.toReplace, changes: doc.data } } },
]);
const bulkPromise = elBulk({ refresh: true, timeout: BULK_TIMEOUT, body: bodyUpdate });
Expand Down Expand Up @@ -4170,7 +4170,7 @@ export const elUpdateEntityConnections = async (elements) => {
const bodyUpdate = elements.flatMap((doc) => {
const refField = isStixRefRelationship(doc.relationType) && isInferredIndex(doc._index) ? ID_INFERRED : ID_INTERNAL;
return [
{ update: { _index: doc._index, _id: doc.id, retry_on_conflict: ES_RETRY_ON_CONFLICT } },
{ update: { _index: doc._index, _id: doc._id ?? doc.id, retry_on_conflict: ES_RETRY_ON_CONFLICT } },
{
script: {
source,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const up = async (next) => {
.map((att) => {
const newId = generateStandardId(att.entity_type, att);
return [
{ update: { _index: att._index, _id: att.id } },
{ update: { _index: att._index, _id: att._id } },
{ doc: { standard_id: newId, x_opencti_stix_ids: [] } },
];
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const up = async (next) => {
.filter((n) => n.entity_type !== ENTITY_TYPE_INDICATOR)
.map((att) => {
return [
{ update: { _index: att._index, _id: att.id } },
{ update: { _index: att._index, _id: att._id } },
{ doc: { [buildRefRelationKey(RELATION_INDICATES)]: null } },
];
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const up = async (next) => {
const op = attacks
.map((att) => {
return [
{ update: { _index: att._index, _id: att.id } },
{ update: { _index: att._index, _id: att._id } },
{ doc: { aliases: [], i_aliases_ids: [], x_opencti_stix_ids: [] } },
];
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const up = async (next) => {
const op = attacks
.map((att) => {
return [
{ update: { _index: att._index, _id: att.id } },
{ update: { _index: att._index, _id: att._id } },
{ doc: { aliases: [], i_aliases_ids: [], x_opencti_stix_ids: [] } },
];
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const up = async (next) => {
.map((att) => {
const newId = generateStandardId(att.entity_type, att);
return [
{ update: { _index: att._index, _id: att.id } },
{ update: { _index: att._index, _id: att._id } },
{ doc: { standard_id: newId, x_opencti_stix_ids: [] } },
];
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const up = async (next) => {
identity_class: entity.identity_class === 'sector' ? 'class' : entity.identity_class,
});
return [
{ update: { _index: entity._index, _id: entity.id } },
{ update: { _index: entity._index, _id: entity._id } },
{
doc: {
i_aliases_ids: newAliasIds,
Expand All @@ -48,7 +48,7 @@ export const up = async (next) => {
const newAliasIds = generateAliases([entity.name, ...(entity.x_opencti_aliases || [])], {
x_opencti_location_type: entity.x_opencti_location_type,
});
return [{ update: { _index: entity._index, _id: entity.id } }, { doc: { i_aliases_ids: newAliasIds } }];
return [{ update: { _index: entity._index, _id: entity._id } }, { doc: { i_aliases_ids: newAliasIds } }];
})
.flat();
bulkOperations.push(...op);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const up = async (next) => {
.map((entity) => {
const newStandardId = generateStandardId(ENTITY_TYPE_INCIDENT, entity);
return [
{ update: { _index: entity._index, _id: entity.id } },
{ update: { _index: entity._index, _id: entity._id } },
{
doc: {
// Fix bad fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const up = async (next) => {
const op = attacks
.map((att) => {
return [
{ update: { _index: att._index, _id: att.id } },
{ update: { _index: att._index, _id: att._id } },
{ doc: { aliases: [], i_aliases_ids: [], x_opencti_stix_ids: [] } },
];
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const up = async (next) => {
default:
status = workflowStatusClosed;
}
return [{ update: { _index: report._index, _id: report.id } }, { doc: { status_id: status.id } }];
return [{ update: { _index: report._index, _id: report._id } }, { doc: { status_id: status.id } }];
})
.flat();
bulkOperations.push(...op);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const up = async (next) => {
.map((att) => {
const newId = generateStandardId(att.entity_type, att);
return [
{ update: { _index: att._index, _id: att.id } },
{ update: { _index: att._index, _id: att._id } },
{ doc: { standard_id: newId, x_opencti_stix_ids: [] } },
];
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const up = async (next) => {
const bulkOperations = entities.map((entity) => {
const aliasIds = generateAliasesIdsForInstance(entity);
return [
{ update: { _index: entity._index, _id: entity.id } },
{ update: { _index: entity._index, _id: entity._id } },
{ doc: { [iAliasedIds.name]: aliasIds } },
];
}).flat();
Expand Down

0 comments on commit 1948fa5

Please sign in to comment.