Skip to content

Commit

Permalink
adding addiional params findingIds, startTime and endTime
Browse files Browse the repository at this point in the history
Signed-off-by: Riya Saxena <[email protected]>
  • Loading branch information
riysaxen-amzn committed Feb 29, 2024
1 parent a360cc7 commit b9d9211
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,25 @@ class TransportGetFindingsSearchAction @Inject constructor(
if (!getFindingsRequest.findingId.isNullOrBlank())
queryBuilder.filter(QueryBuilders.termQuery("_id", getFindingsRequest.findingId))

if (!getFindingsRequest.findingIds.isNullOrEmpty()) {
queryBuilder.filter(QueryBuilders.termsQuery("id", getFindingsRequest.findingIds))
}

if (getFindingsRequest.monitorId != null) {
queryBuilder.filter(QueryBuilders.termQuery("monitor_id", getFindingsRequest.monitorId))
} else if (getFindingsRequest.monitorIds.isNullOrEmpty() == false) {
queryBuilder.filter(QueryBuilders.termsQuery("monitor_id", getFindingsRequest.monitorIds))
}

if (getFindingsRequest.startTime != null && getFindingsRequest.endTime != null) {
val startTime = getFindingsRequest.startTime!!.toEpochMilli()
val endTime = getFindingsRequest.endTime!!.toEpochMilli()
val timeRangeQuery = QueryBuilders.rangeQuery("timestamp")
.from(startTime) // Greater than or equal to start time
.to(endTime) // Less than or equal to end time
queryBuilder.filter(timeRangeQuery)
}

if (!detectionType.isNullOrBlank()) {
val nestedQueryBuilder = QueryBuilders.nestedQuery(
"queries",
Expand Down Expand Up @@ -182,7 +195,6 @@ class TransportGetFindingsSearchAction @Inject constructor(
)
)
}

searchSourceBuilder.query(queryBuilder)

client.threadPool().threadContext.stashContext().use {
Expand Down

0 comments on commit b9d9211

Please sign in to comment.