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

Reset the ShardTargetType after serializing inner hits. #12261

Merged

Conversation

martijnvg
Copy link
Member

This fixes a bug where only the first top level search hit has a shard target and any subsequent search hits don't.

This bug was reported in the forum: https://discuss.elastic.co/t/elasticsearch-innerhits-java-api-causing-npe/25532

@@ -808,7 +810,9 @@ public void writeTo(StreamOutput out, InternalSearchHits.StreamContext context)
out.writeVInt(innerHits.size());
for (Map.Entry<String, InternalSearchHits> entry : innerHits.entrySet()) {
out.writeString(entry.getKey());
entry.getValue().writeTo(out, InternalSearchHits.streamContext().streamShardTarget(InternalSearchHits.StreamContext.ShardTargetType.NO_STREAM));
ShardTargetType previous = InternalSearchHits.streamContext().streamShardTarget();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a better name for this variable? I'm not really sure what previous is here? Could this not just be shardTarget?

Copy link
Member Author

Choose a reason for hiding this comment

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

it is the ShardTargetType of the current hit and we remember that so that it doesn't get lost when the inner_hits are serialised. Because for the inner hits we don't need shard target, because that is always the same as the top level search hit (shard and index that is).

I'm ok with renaming it to shardTarget.

@colings86
Copy link
Contributor

Left a minor comment but otherwise it LGTM

@martijnvg martijnvg force-pushed the inner_hits/search_hit_missing_shard_target branch from 9847926 to c955970 Compare August 14, 2015 20:12
This fixes a bug where only the first top level search hit has a shard target and any subsequent search hits don't.
@martijnvg martijnvg force-pushed the inner_hits/search_hit_missing_shard_target branch from c955970 to 942d040 Compare August 14, 2015 20:38
@martijnvg martijnvg removed the review label Aug 14, 2015
@martijnvg martijnvg merged commit 942d040 into elastic:master Aug 14, 2015
martijnvg added a commit that referenced this pull request Aug 17, 2015
martijnvg added a commit that referenced this pull request Aug 17, 2015
@clintongormley clintongormley added :Search/Search Search-related issues that do not fall into other categories and removed :Inner Hits 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 v2.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants