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

Correctly handle mixed object paths in XContentMapValues #65539

Merged
merged 7 commits into from
Dec 1, 2020

Conversation

romseygeek
Copy link
Contributor

@romseygeek romseygeek commented Nov 26, 2020

When we have an object that looks like this:

{
  "foo" : {
    "cat", "meow"
  },
  "foo.bar" : "baz"

where the inner objects of foo are defined both as json objects and via
dot notation, then XContentMapValues.extractValue() will only descend
through the json object and will not collect values from the dot notated paths.
In these cases, the foo.bar values will not be returned in the fields
section of a search response.

This commit adds the ability to check both paths, ensuring that all relevant
values get returned as part of fields.

Fixes #65499

@romseygeek romseygeek added >bug :Search/Search Search-related issues that do not fall into other categories v8.0.0 v7.11.0 labels Nov 26, 2020
@romseygeek romseygeek self-assigned this Nov 26, 2020
@elasticmachine elasticmachine added the Team:Search Meta label for search team label Nov 26, 2020
@elasticmachine
Copy link
Collaborator

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

@romseygeek
Copy link
Contributor Author

I've marked this for 7.11 but we could conceivably backport it to 7.10.1 as well.

@romseygeek
Copy link
Contributor Author

@elasticmachine update branch

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.

I took a look since the case this issue fixes also might be interesting for #65386 and the change here makes sense to me. LGTM, but maybe you want to wait for a second pair of eyes here.

Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

LGTM

@jtibshirani
Copy link
Contributor

Thanks @romseygeek for fixing this! I noticed there's a related but slightly different edge case:

{
  "foo" : {
    "bar", "meow"
  },
  "foo.bar" : "baz"
}

Surprisingly, we allow documents to specify a field both in structured object and dot notation. When parsing, we index both values as if it were specified as an array.

Your PR fixes the problem for XContentMapValues#extractRawValues -- maybe we could add a quick test for that. I could file a separate issue about field fetching/ XContentMapValues#extractValue, which still doesn't handle this correctly.

@romseygeek
Copy link
Contributor Author

Your PR fixes the problem for XContentMapValues#extractRawValues -- maybe we could add a quick test for that. I could file a separate issue about field fetching/ XContentMapValues#extractValue, which still doesn't handle this correctly.

I've pushed a test for your second case. extractValue is trickier because it only returns a single value, so let's deal with that in a separate issue.

@romseygeek romseygeek merged commit 0d7a306 into elastic:master Dec 1, 2020
@romseygeek romseygeek deleted the bug/object-fields-fetch branch December 1, 2020 09:57
romseygeek added a commit that referenced this pull request Dec 1, 2020
When we have an object that looks like this:

```
{
  "foo" : {
    "cat": "meow"
  },
  "foo.bar" : "baz"
```

where the inner objects of foo are defined both as json objects and via
dot notation, then XContentMapValues.extractValue() will only descend
through the json object and will not collect values from the dot notated paths.
In these cases, the foo.bar values will not be returned in the fields
section of a search response.

This commit adds the ability to check both paths, ensuring that all relevant
values get returned as part of fields.

Fixes #65499
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 Team:Search Meta label for search team v7.11.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fields API won't extract field that begins with the name of an object
6 participants