Skip to content

Commit

Permalink
fix(fetch_available_indices): include indices with data within date r…
Browse files Browse the repository at this point in the history
…ange regardless of creation date

Previously, `fetchAvailableIndices` only considered indices whose creation dates fell within the specified date range. This missed indices that were created outside the date range but contained data within it. This fix updates the function to also include indices that have data within the specified date range by performing an additional search aggregation.

- Return back `getRequestBody` helper to build the search request for fetching indices with data in range.
- Improve error handling for invalid date formats with more specific messages.
- Update tests to reflect the new logic and error messages.
  • Loading branch information
kapral18 committed Oct 28, 2024
1 parent c53b2d3 commit a29630f
Show file tree
Hide file tree
Showing 3 changed files with 399 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { SearchRequest } from '@elastic/elasticsearch/lib/api/types';

export const getRequestBody = ({
indexPattern,
startDate = 'now-7d/d',
endDate = 'now/d',
}: {
indexPattern: string;
startDate: string;
endDate: string;
}): SearchRequest => ({
index: indexPattern,
aggs: {
index: {
terms: {
field: '_index',
},
},
},
size: 0,
query: {
bool: {
must: [],
filter: [
{
range: {
'@timestamp': {
format: 'strict_date_optional_time',
gte: startDate,
lte: endDate,
},
},
},
],
should: [],
must_not: [],
},
},
});
Loading

0 comments on commit a29630f

Please sign in to comment.