Skip to content

Commit

Permalink
Support range filters for csv reports (opensearch-project#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuali925 authored and zhongnansu committed Oct 27, 2021
1 parent 47bafac commit 988db2a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
1 change: 0 additions & 1 deletion kibana-reports/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
"prettier": "2.0.5",
"react-test-renderer": "^16.13.1",
"ts-jest": "^26.1.0",
"tsc": "^1.20150623.0",
"typescript": "^3.9.5"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,15 @@ export const replaceQueryURL = (pageUrl) => {
let [, fromDateStringMatch, toDateStringMatch] = queryUrl.match(
timeRangeMatcher
);
fromDateString = decodeURIComponent(fromDateStringMatch.replace(/[']+/g, ''));
const fromDateString = decodeURIComponent(
fromDateStringMatch.replace(/[']+/g, '')
);

// convert time range to from date format in case time range is relative
const fromDateFormat = dateMath.parse(fromDateString);
toDateString = decodeURIComponent(toDateStringMatch.replace(/[']+/g, ''));
const toDateString = decodeURIComponent(
toDateStringMatch.replace(/[']+/g, '')
);
const toDateFormat = dateMath.parse(toDateString, { roundUp: true });

// replace to and from dates with absolute date
Expand Down
21 changes: 18 additions & 3 deletions kibana-reports/server/routes/utils/dataReportHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
* permissions and limitations under the License.
*/

import { DATA_REPORT_CONFIG } from './constants';

import esb, { Sort } from 'elastic-builder';
import moment from 'moment';
import converter from 'json-2-csv';
import _ from 'lodash';
import moment from 'moment';
import { DATA_REPORT_CONFIG } from './constants';

export var metaData = {
saved_search_id: <string>null,
Expand Down Expand Up @@ -81,6 +80,14 @@ export const buildQuery = (report, is_count) => {
}
requestBody.minimumShouldMatch(1);
break;
case 'range':
const builder = esb.rangeQuery(item.meta.key);
if (item.meta.params.gte) builder.gte(item.meta.params.gte);
if (item.meta.params.lte) builder.lte(item.meta.params.lte);
if (item.meta.params.gt) builder.gt(item.meta.params.gt);
if (item.meta.params.lt) builder.lt(item.meta.params.lt);
requestBody.must(builder);
break;
}
break;
case true:
Expand All @@ -106,6 +113,14 @@ export const buildQuery = (report, is_count) => {
}
requestBody.minimumShouldMatch(1);
break;
case 'range':
const builder = esb.rangeQuery(item.meta.key);
if (item.meta.params.gte) builder.gte(item.meta.params.gte);
if (item.meta.params.lte) builder.lte(item.meta.params.lte);
if (item.meta.params.gt) builder.gt(item.meta.params.gt);
if (item.meta.params.lt) builder.lt(item.meta.params.lt);
requestBody.mustNot(builder);
break;
}
break;
}
Expand Down
5 changes: 0 additions & 5 deletions kibana-reports/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9810,11 +9810,6 @@ ts-jest@^26.1.0:
semver "7.x"
yargs-parser "20.x"

tsc@^1.20150623.0:
version "1.20150623.0"
resolved "https://registry.yarnpkg.com/tsc/-/tsc-1.20150623.0.tgz#4ebc3c774e169148cbc768a7342533f082c7a6e5"
integrity sha1-Trw8d04WkUjLx2inNCUz8ILHpuU=

tsconfig-paths@^3.9.0:
version "3.9.0"
resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.9.0.tgz#098547a6c4448807e8fcb8eae081064ee9a3c90b"
Expand Down

0 comments on commit 988db2a

Please sign in to comment.