Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix document counts with an empty index set #3291

Merged
merged 4 commits into from Jan 4, 2017
Merged

Fix document counts with an empty index set #3291

merged 4 commits into from Jan 4, 2017

Conversation

@bernd
Copy link
Member

@bernd bernd commented Jan 3, 2017

Return 0 if there are no indices in the given index set. If we run the query with an empty index list, Elasticsearch will count all documents in all indices and thus return a wrong count.

@bernd bernd added this to the 2.2.0 milestone Jan 3, 2017
@joschi joschi self-assigned this Jan 3, 2017
Copy link
Contributor

@joschi joschi left a comment

I guess this will create a merge conflict with #3288 (just FYI).

@@ -45,6 +45,12 @@ public long total() {
public long total(final IndexSet indexSet) {
final String[] names = indexSet.getManagedIndicesNames();

// Return 0 if there are no indices in the given index set. If we run the query with an empty index list,
// Elasticsearch will count all documents in all indices and thus return a wrong count.
if (names.length == 0) {

This comment has been minimized.

@joschi

joschi Jan 3, 2017
Contributor

This check should probably also be added to the Counts#total() method.

If none of the index set contains an index and other indices (not managed by Graylog) exist in the Elasticsearch cluster, the returned value might be wrong.

This comment has been minimized.

@bernd

bernd Jan 3, 2017
Author Member

Good point, fixed. 👍

// Return 0 if there are no indices in the given index set. If we run the query with an empty index list,
// Elasticsearch will count all documents in all indices and thus return a wrong count.
if (names.length == 0) {
if (requireNonNull(indexNames).length == 0) {

This comment has been minimized.

@joschi

joschi Jan 3, 2017
Contributor

Why the requireNonNull() here?

If indexNames is null, it will throw an NPE anyway.

@bernd bernd force-pushed the fix-index-counts branch to aa3d2e7 Jan 3, 2017
@joschi
joschi approved these changes Jan 4, 2017
@joschi joschi merged commit f17c81e into master Jan 4, 2017
4 checks passed
4 checks passed
@garybot2
ci-web-linter Jenkins build graylog-pr-linter-check 1240 has succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
licence/cla Contributor License Agreement is signed.
Details
@joschi joschi deleted the fix-index-counts branch Jan 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants