Skip to content

Commit

Permalink
[api] Fix filters with values to null (#419)
Browse files Browse the repository at this point in the history
* [api] Fix filters with values to null

* Sanitize

* Sanitize

* Sanitize

* Sanitize
  • Loading branch information
Samuel Hassine authored Jan 22, 2020
1 parent bc4159b commit 3c5d516
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
26 changes: 12 additions & 14 deletions opencti-platform/opencti-graphql/src/database/elasticSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,22 +584,20 @@ export const elPaginate = async (indexName, options) => {
for (let index = 0; index < validFilters.length; index += 1) {
const valuesFiltering = [];
const { key, values, operator = 'eq' } = validFilters[index];
if (values === null) {
mustnot = append({ exists: { field: key } }, mustnot);
} else {
for (let i = 0; i < values.length; i += 1) {
if (operator === 'eq' || operator === 'match') {
valuesFiltering.push({
match_phrase: {
[`${dateFields.includes(key) || operator === 'match' ? key : `${key}.keyword`}`]: values[i]
}
});
} else {
valuesFiltering.push({ range: { [key]: { [operator]: values[i] } } });
}
for (let i = 0; i < values.length; i += 1) {
if (values[i] === null) {
mustnot = append({ exists: { field: key } }, mustnot);
} else if (operator === 'eq' || operator === 'match') {
valuesFiltering.push({
match_phrase: {
[`${dateFields.includes(key) || operator === 'match' ? key : `${key}.keyword`}`]: values[i]
}
});
} else {
valuesFiltering.push({ range: { [key]: { [operator]: values[i] } } });
}
must = append({ bool: { should: valuesFiltering, minimum_should_match: 1 } }, must);
}
must = append({ bool: { should: valuesFiltering, minimum_should_match: 1 } }, must);
}
}
if (orderBy !== null && orderBy.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
deleteRelationsByFromAndTo
} from '../database/grakn';
import { findById as findMarkingDefintionById } from './markingDefinition';
import { elCount } from '../database/elasticSearch';
import { elCount, INDEX_STIX_ENTITIES } from '../database/elasticSearch';
import { generateFileExportName, upload } from '../database/minio';
import { connectorsForExport } from './connector';
import { createWork, workToExportFile } from './work';
Expand Down Expand Up @@ -48,8 +48,8 @@ export const stixDomainEntitiesTimeSeries = args => {
};

export const stixDomainEntitiesNumber = args => ({
count: elCount('stix_domain_entities', args),
total: elCount('stix_domain_entities', dissoc('endDate', args))
count: elCount(INDEX_STIX_ENTITIES, args),
total: elCount(INDEX_STIX_ENTITIES, dissoc('endDate', args))
});
// endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export const up = async next => {
export const down = async next => {
// Reverting this cannot be done because we define the schema directly with the code...
next();
};
};

0 comments on commit 3c5d516

Please sign in to comment.