Skip to content

Set maxScore for empty TopDocs to Nan rather than 0 #32938

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

Merged
merged 6 commits into from
Aug 22, 2018

Conversation

javanna
Copy link
Member

@javanna javanna commented Aug 17, 2018

We used to set maxScore to 0 within TopDocs in situations where there is really no score as the size was set to 0 and scores were not even tracked. In such scenarios, Float.Nan is more appropriate, which gets converted to max_score: null on the REST layer. That's also more consistent with lucene which set maxScore to Float.Nan when merging empty TopDocs (see TopDocs#merge).

We used to set `maxScore` to `0` within `TopDocs` in situations where there is really no score as the size was set to `0` and scores were not even tracked. In such scenarios, `Float.Nan` is more appropriate, which gets converted to `max_score: null` on the REST layer. That's also more consistent with lucene which set `maxScore` to `Float.Nan` when merging empty `TopDocs` (see `TopDocs#merge`).
@javanna javanna added >bug :Search/Search Search-related issues that do not fall into other categories v7.0.0 labels Aug 17, 2018
@javanna javanna requested a review from jpountz August 17, 2018 10:49
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

@@ -513,7 +513,7 @@ public void testSearchWithSuggest() throws IOException {
assertNull(searchResponse.getAggregations());
assertEquals(Collections.emptyMap(), searchResponse.getProfileResults());
assertEquals(0, searchResponse.getHits().totalHits);
assertEquals(0f, searchResponse.getHits().getMaxScore(), 0f);
assertEquals(Float.NaN, searchResponse.getHits().getMaxScore(), 0f);
assertEquals(0, searchResponse.getHits().getHits().length);
assertEquals(1, searchResponse.getSuggest().size());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not too happy that all the failures I got came from integration tests and docs tests. I added some assertions to QueryPhaseTests but maybe that is not enough. Suggestions are welcome on where to add tests for this change.

@javanna javanna force-pushed the fix/empty_top_docs_nan branch from c7c637c to 9c19b4b Compare August 17, 2018 15:30
@javanna javanna merged commit 393eec1 into elastic:master Aug 22, 2018
@javanna
Copy link
Member Author

javanna commented Aug 22, 2018

thanks @jpountz !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search/Search Search-related issues that do not fall into other categories v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants