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 bug in NestedUtils.partitionByChildren() #97970

Merged
merged 3 commits into from
Jul 26, 2023

Conversation

romseygeek
Copy link
Contributor

If multiple fields appeared between two child scopes, the following children
would be incorrectly assigned to the parent scope.

@romseygeek romseygeek added >non-issue :Search/Search Search-related issues that do not fall into other categories v8.10.0 v8.9.1 v7.17.13 labels Jul 26, 2023
@romseygeek romseygeek self-assigned this Jul 26, 2023
@elasticsearchmachine elasticsearchmachine added the Team:Search Meta label for search team label Jul 26, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)

Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

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

Thanks, I left a comment to further simplify the new FieldFetcherTest and maybe add assertions on the whole output there now that its smaller.

var results = fetchFields(mapperService, source, fieldAndFormatList("*", null, false));
SearchHit searchHit = new SearchHit(0);
searchHit.addDocumentFields(results, Map.of());
assertThat(Strings.toString(searchHit), containsString("\"ml.top_classes\":"));
Copy link
Member

Choose a reason for hiding this comment

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

I think this boils it down even further to make the test more succinct. At least this fails without your above changes and passes otherwise:

        MapperService mapperService = createMapperService("""
            { "_doc" : { "properties": {
                                 "ml": {
                                   "properties": {
                                     "feature_importance": {
                                       "type": "nested",
                                       "dynamic": "false",
                                       "properties": {
                                         "feature_name": {
                                           "type": "keyword"
                                         }
                                       }
                                     },
                                     "is_training": {
                                       "type": "boolean"
                                     },
                                     "prediction_probability": {
                                       "type": "double"
                                     },
                                     "top_classes": {
                                       "type": "nested",
                                       "properties": {
                                         "class_name": {
                                           "type": "keyword"
                                         }
                                       }
                                     }
                                   }
                                 }
            }}}
            """);

        String source = """
            {
                       "ml": {
                         "y_prediction": "no",
                         "top_classes": [
                           {
                             "class_name": "no"
                           },
                           {
                             "class_name": "yes"
                           }
                         ],
                         "prediction_probability": 0.978734716971892,
                         "is_training": false
                       }
                     }
            """;

Copy link
Member

Choose a reason for hiding this comment

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

Maybe if that version is working for you, could you also change the test slightly so we don't just asset on the substring but actually check the whole output map? Shouldn't be too deep any more now and makes the assertion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's important to have more than one entry before and between the nested mappers, to cover all the cases properly? So yes, the cut down version will cover the specific bug here but I'd like to keep more in there to catch regressions.

@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.9
7.17 Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 97970

romseygeek added a commit to romseygeek/elasticsearch that referenced this pull request Jul 26, 2023
If multiple fields appeared between two child scopes, the following children
would be incorrectly assigned to the parent scope.
elasticsearchmachine pushed a commit that referenced this pull request Jul 26, 2023
If multiple fields appeared between two child scopes, the following children
would be incorrectly assigned to the parent scope.
romseygeek added a commit to romseygeek/elasticsearch that referenced this pull request Jul 26, 2023
If multiple fields appeared between two child scopes, the following children
would be incorrectly assigned to the parent scope.
elasticsearchmachine pushed a commit that referenced this pull request Jul 26, 2023
If multiple fields appeared between two child scopes, the following children
would be incorrectly assigned to the parent scope.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>non-issue :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team v7.17.13 v8.9.1 v8.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants