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

Prevent duplicate fields when mixing parent and root nested includes #27072

Merged
merged 3 commits into from
Oct 31, 2017

Conversation

original-brownbear
Copy link
Member

Fixes #26990 (I think :))

Fixed this by traversing the tree of Nested instances in the Builder for RootObjectMapper since it seemed to be the one place before instantiating the mappers where I can mutate builders and have the full tree of Nested available to me.
So my logic was:

  • The duplicate fields arise from a child nested by more than one level, that is directly included in the root and also transitively included via a chain of parent(s).
    => Set all include_in_root to false, that are already covered by transitive chains of include_in_parent == true

Copy link
Contributor

@jpountz jpountz left a comment

Choose a reason for hiding this comment

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

I think you found the right place to fix the issue, however I spotted a bug (see comments).

Nested nested = child.nested;
boolean included;
if (parentIncluded) {
included = nested.isNested() && nested.isIncludeInParent();
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it is correct: included should also true if nested.isIncludeInRoot is true? Otherwise we might recurse on a wrong value.

boolean included;
if (parentIncluded) {
included = nested.isNested() && nested.isIncludeInParent();
if (included) {
Copy link
Contributor

Choose a reason for hiding this comment

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

However I agree that we should test for if (nested.isNested() && nested.isIncludeInParent()) here.

@original-brownbear
Copy link
Member Author

@jpountz fixed + added a test that reproduced the bug you found. Also a little more readable now I think/hope, since now it's clearly visible that we're fixing only if included in parent and included in root are true simultaneously :)

Copy link
Contributor

@jpountz jpountz left a comment

Choose a reason for hiding this comment

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

I just left a naming suggestion, but the change looks good to me!

ObjectMapper.Builder child = (ObjectMapper.Builder) mapper;
Nested nested = child.nested;
boolean isNested = nested.isNested();
boolean includedInParent = parentIncluded && isNested && nested.isIncludeInParent();
Copy link
Contributor

Choose a reason for hiding this comment

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

should we rename to something like includeInRootViaParent to make it clearer what this is about?

@original-brownbear
Copy link
Member Author

original-brownbear commented Oct 27, 2017

@jpountz I agree renamed that variable :)

@original-brownbear
Copy link
Member Author

@jpountz build failure looks unrelated, should we retrigger Jenkins?

@jpountz
Copy link
Contributor

jpountz commented Oct 27, 2017

@elasticmachine please test it

@original-brownbear
Copy link
Member Author

@jpountz hmm no seems, there's an actual issue now. Failed the same way for me locally, sorry. Will fix shortly.

@original-brownbear
Copy link
Member Author

rebase against master fixed it locally, let's see what Jenkins says

@original-brownbear
Copy link
Member Author

I see the same error here for another PR and it seems to happen randomly locally https://elasticsearch-ci.elastic.co/job/elastic+elasticsearch+pull-request/5141/console so not related it seems.

@original-brownbear
Copy link
Member Author

@elasticmachine please test it

@original-brownbear
Copy link
Member Author

@jpountz instability seems to be handled here #27146 => good to squash + merge right? :)

@jpountz
Copy link
Contributor

jpountz commented Oct 27, 2017

Sure, I'll merge. Thanks @original-brownbear !

@original-brownbear
Copy link
Member Author

@jpountz np + thanks for the review :)

@original-brownbear
Copy link
Member Author

@jpountz ping :)

@jpountz jpountz merged commit a4c159e into elastic:master Oct 31, 2017
@jpountz
Copy link
Contributor

jpountz commented Oct 31, 2017

Thanks @original-brownbear !

@original-brownbear original-brownbear deleted the 26990 branch October 31, 2017 09:06
@original-brownbear
Copy link
Member Author

np @jpountz :)

jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Nov 1, 2017
* master:
  Enhances exists queries to reduce need for `_field_names` (elastic#26930)
  Added new terms_set query
  Set request body to required to reflect the code base (elastic#27188)
  Update Docker docs for 6.0.0-rc2 (elastic#27166)
  Add version 6.0.0
  Docs: restore now fails if it encounters incompatible settings (elastic#26933)
  Convert index blocks to cluster block exceptions (elastic#27050)
  [DOCS] Link remote info API in Cross Cluster Search docs page
  Fix Laplace scorer to multiply by alpha (and not add) (elastic#27125)
  [DOCS] Clarify migrate guide and search request validation
  Raise IllegalArgumentException if query validation failed (elastic#26811)
  prevent duplicate fields when mixing parent and root nested includes (elastic#27072)
  TopHitsAggregator must propagate calls to `setScorer`. (elastic#27138)
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Nov 2, 2017
* master:
  Remove checkpoint tracker bit sets setting
  Fix stable BWC branch detection logic
  Fix logic detecting unreleased versions
  Enhances exists queries to reduce need for `_field_names` (elastic#26930)
  Added new terms_set query
  Set request body to required to reflect the code base (elastic#27188)
  Update Docker docs for 6.0.0-rc2 (elastic#27166)
  Add version 6.0.0
  Docs: restore now fails if it encounters incompatible settings (elastic#26933)
  Convert index blocks to cluster block exceptions (elastic#27050)
  [DOCS] Link remote info API in Cross Cluster Search docs page
  Fix Laplace scorer to multiply by alpha (and not add) (elastic#27125)
  [DOCS] Clarify migrate guide and search request validation
  Raise IllegalArgumentException if query validation failed (elastic#26811)
  prevent duplicate fields when mixing parent and root nested includes (elastic#27072)
  TopHitsAggregator must propagate calls to `setScorer`. (elastic#27138)
jasontedor added a commit that referenced this pull request Nov 2, 2017
* master:
  Lazy initialize checkpoint tracker bit sets
  Remove checkpoint tracker bit sets setting
  Fix stable BWC branch detection logic
  Fix logic detecting unreleased versions
  Enhances exists queries to reduce need for `_field_names` (#26930)
  Added new terms_set query
  Set request body to required to reflect the code base (#27188)
  Update Docker docs for 6.0.0-rc2 (#27166)
  Add version 6.0.0
  Docs: restore now fails if it encounters incompatible settings (#26933)
  Convert index blocks to cluster block exceptions (#27050)
  [DOCS] Link remote info API in Cross Cluster Search docs page
  Fix Laplace scorer to multiply by alpha (and not add) (#27125)
  [DOCS] Clarify migrate guide and search request validation
  Raise IllegalArgumentException if query validation failed (#26811)
  prevent duplicate fields when mixing parent and root nested includes (#27072)
  TopHitsAggregator must propagate calls to `setScorer`. (#27138)
jasontedor added a commit that referenced this pull request Nov 2, 2017
* 6.x:
  Lazy initialize checkpoint tracker bit sets
  Remove checkpoint tracker bit sets setting
  Tests: Fix FullClusterRestartIT.testSnapshotRestore test failing in 6.x (#27218)
  Fix FullClusterRestartIT using lenient booleans with 6.0
  Fix stable BWC branch detection logic
  Add version 6.0.0
  Fix logic detecting unreleased versions
  Skips exists query tests on unsupported versions
  Enhances exists queries to reduce need for `_field_names` (#26930)
  Added new terms_set query
  Set request body to required to reflect the code base (#27188)
  Update Docker docs for 6.0.0-rc2 (#27166)
  Docs: restore now fails if it encounters incompatible settings (#26933)
  Convert index blocks to cluster block exceptions (#27050)
  [DOCS] Link remote info API in Cross Cluster Search docs page
  prevent duplicate fields when mixing parent and root nested includes (#27072)
  TopHitsAggregator must propagate calls to `setScorer`. (#27138)
@clintongormley clintongormley changed the title #26990 prevent duplicate fields when mixing parent and root nested includes Prevent duplicate fields when mixing parent and root nested includes Nov 6, 2017
@clintongormley clintongormley added :Search/Search Search-related issues that do not fall into other categories and removed :Nested Docs labels Feb 14, 2018
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 v6.1.0 v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants