Skip to content

Commit

Permalink
Fix parsing empty query
Browse files Browse the repository at this point in the history
  • Loading branch information
Zacqary committed Apr 28, 2020
1 parent bfaf980 commit 0c7aefa
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,19 @@ const getCurrentValueFromAggregations = (

const getParsedFilterQuery: (
filterQuery: string | undefined
) => Record<string, any> = filterQuery => {
if (!filterQuery) return {};
) => Array<Record<string, any>> = filterQuery => {
if (!filterQuery) return [];
try {
return JSON.parse(filterQuery).bool;
return [JSON.parse(filterQuery).bool];
} catch (e) {
return {
query_string: {
query: filterQuery,
analyze_wildcard: true,
return [
{
query_string: {
query: filterQuery,
analyze_wildcard: true,
},
},
};
];
}
};

Expand Down Expand Up @@ -159,7 +161,7 @@ export const getElasticsearchMetricQuery = (
return {
query: {
bool: {
filter: [...rangeFilters, ...metricFieldFilters, parsedFilterQuery],
filter: [...rangeFilters, ...metricFieldFilters, ...parsedFilterQuery],
},
},
size: 0,
Expand Down

0 comments on commit 0c7aefa

Please sign in to comment.