Skip to content

Commit

Permalink
Ensure we're using the data view time field for the sort param too
Browse files Browse the repository at this point in the history
  • Loading branch information
davismcphee committed May 8, 2024
1 parent d857ea9 commit 0643fe2
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,17 @@ export function updateSearchSource(
alertLimit?: number
): { searchSource: ISearchSource; filterToExcludeHitsFromPreviousRun: Filter | null } {
const isGroupAgg = isGroupAggregation(params.termField);
const timeFieldName = params.timeField || index.timeFieldName;
const timeField = index.getTimeField();

if (!timeFieldName) {
throw new Error('Invalid data view without timeFieldName.');
if (!timeField) {
throw new Error(`Data view with ID ${index.id} no longer contains a time field.`);
}

searchSource.setField('size', isGroupAgg ? 0 : params.size);

const field = index.getTimeField();
const filters = [
buildRangeFilter(
field!,
timeField,
{ lte: dateEnd, gte: dateStart, format: 'strict_date_optional_time' },
index
),
Expand All @@ -135,7 +134,7 @@ export function updateSearchSource(
// add additional filter for documents with a timestamp greater than
// the timestamp of the previous run, so that those documents are not counted twice
filterToExcludeHitsFromPreviousRun = buildRangeFilter(
field!,
timeField,
{ gt: latestTimestamp, format: 'strict_date_optional_time' },
index
);
Expand All @@ -150,7 +149,7 @@ export function updateSearchSource(
searchSourceChild.setField('filter', filters as Filter[]);
searchSourceChild.setField('sort', [
{
[timeFieldName]: {
[timeField.name]: {
order: SortDirection.desc,
format: 'strict_date_optional_time||epoch_millis',
},
Expand Down

0 comments on commit 0643fe2

Please sign in to comment.