Skip to content

Commit

Permalink
[api] Prevent finding user-xx when looking for user entity type
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-julien committed Jun 18, 2021
1 parent 0b40d0e commit 4071c1e
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions opencti-platform/opencti-graphql/src/database/elasticSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ export const elCount = (user, indexName, options = {}) => {
path: 'connections',
query: {
bool: {
must: [{ match_phrase: { [`connections.internal_id`]: fromId } }],
must: [{ match_phrase: { [`connections.internal_id.keyword`]: fromId } }],
},
},
},
Expand All @@ -466,7 +466,7 @@ export const elCount = (user, indexName, options = {}) => {
const filters = [];
for (let index = 0; index < toTypes.length; index += 1) {
filters.push({
match_phrase: { 'connections.types': toTypes[index] },
match_phrase: { 'connections.types.keyword': toTypes[index] },
});
}
must = R.append(
Expand Down Expand Up @@ -603,7 +603,7 @@ export const elFindByFromAndTo = async (user, fromId, toId, relationshipType) =>
path: 'connections',
query: {
bool: {
must: [{ match_phrase: { 'connections.internal_id': fromId } }],
must: [{ match_phrase: { 'connections.internal_id.keyword': fromId } }],
},
},
},
Expand All @@ -613,7 +613,7 @@ export const elFindByFromAndTo = async (user, fromId, toId, relationshipType) =>
path: 'connections',
query: {
bool: {
must: [{ match_phrase: { 'connections.internal_id': toId } }],
must: [{ match_phrase: { 'connections.internal_id.keyword': toId } }],
},
},
},
Expand Down Expand Up @@ -954,7 +954,7 @@ export const elHistogramCount = async (user, type, field, interval, start, end,
const typesFilters = [];
for (let index = 0; index < toTypes.length; index += 1) {
typesFilters.push({
match_phrase: { 'connections.types': toTypes[index] },
match_phrase: { 'connections.types.keyword': toTypes[index] },
});
}
if (typesFilters.length > 0) {
Expand Down Expand Up @@ -1038,7 +1038,10 @@ export const elPaginate = async (user, indexName, options = {}) => {
if (types !== null && types.length > 0) {
const should = R.flatten(
types.map((typeValue) => {
return [{ match_phrase: { entity_type: typeValue } }, { match_phrase: { parent_types: typeValue } }];
return [
{ match_phrase: { 'entity_type.keyword': typeValue } },
{ match_phrase: { 'parent_types.keyword': typeValue } },
];
})
);
must = R.append({ bool: { should, minimum_should_match: 1 } }, must);
Expand Down Expand Up @@ -1704,7 +1707,7 @@ export const elUpdateAttributeValue = (key, previousValue, value) => {
}
index++;
}`;
const query = { match_phrase: { [key]: previousValue } };
const query = { match_phrase: { [`${key}.keyword`]: previousValue } };
return el
.updateByQuery({
index: READ_DATA_INDICES,
Expand Down Expand Up @@ -1777,7 +1780,7 @@ export const elUpdateConnectionsOfElement = (documentId, documentBody) => {
path: 'connections',
query: {
bool: {
must: [{ match_phrase: { [`connections.internal_id`]: documentId } }],
must: [{ match_phrase: { [`connections.internal_id.keyword`]: documentId } }],
},
},
},
Expand Down

0 comments on commit 4071c1e

Please sign in to comment.