When the directory_ index is empty, allIndices will be an empty array, which sets the count query terms index_ aggregation size to 0 which ES does not like.
const countQuery = {
size: 0,
query: searchQuery.query,
aggs: {
collection: {
terms: {
field: "_index",
size: allIndices.length
}
}
}
}
JS Errors
Search error: [1:185] [terms] failed to parse field [size]
Uncaught (in promise) TypeError: countResponse is null