Skip to content

Refactor SearchRequest to be parsed on the coordinating node #13859

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 99 commits into from
Oct 15, 2015

Conversation

colings86
Copy link
Contributor

This change refactors the SearchRequest so it is parsed on the coordinating node and then sent as a serialised object to the shards. The SearchSourceBuilder encompasses the state of the bpdy of the search request (know in the code as source) and is embedded in the SearchRequest. On the shard the SearchSourceBuilder is used to populate the SearchContext where we used to parse the source JSON.

A few things to note:

  • The Java API has been changed to only accept builders in the SearchRequest, SearchRequestBuilder, SearchSourceBuilder and other similar classes. This means that all methods that accepted BytesReference, byte[], String, BytesArray etc. in the search API (and derivatives) should have been removed
  • Some variables inside the SearchSourceBuilder are stored as BytesReference object as their builder objects have not yet been refactored. The SearchSourceBuilder converts the incoming Builder into the BytesReference to serialise to the shards and the parsing of this JSON is still handled in SearchService.parseSource(). Over time these will be refactored so these builders can also be stored as objects in SearchSourceBuilder and serialised to the shards properly.

colings86 and others added 30 commits September 23, 2015 10:44
Lots of NOCOMMITS are in the code as lots of compile errors have been temporarily commented out
This commit removes all the opaque bytes for extra_source and template_source.
Instead source and extra_source etc. are represented as SearchSourceBuilder which can
in-place be modified and is updated with the content of the request parameters.
Template Source is parsed and evaluated which in-turn replaces the actual source.
Not the neatest implementation in the world. Maybe we should consider changing the builders so it is a single builder for sort and a single builder for rescore instead of a list of builders for each?
…refactoring

# Conflicts:
#	core/src/test/java/org/elasticsearch/search/functionscore/DecayFunctionScoreIT.java
#	core/src/test/java/org/elasticsearch/search/functionscore/FunctionScoreFieldValueIT.java
#	core/src/test/java/org/elasticsearch/search/functionscore/FunctionScoreIT.java
#	core/src/test/java/org/elasticsearch/search/rescore/QueryRescorerIT.java
private String[] types = Strings.EMPTY_ARRAY;

private int terminateAfter = DEFAULT_TERMINATE_AFTER;
private SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
Copy link
Contributor

Choose a reason for hiding this comment

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

any chance this can be final?

@s1monw
Copy link
Contributor

s1monw commented Oct 15, 2015

@colings86 this LGTM but I wonder what happened to all the ParseElements like HighlighterParseElement since we used to have all the parsing in there I wonder if we still need id and separately why we don't reuse the code from them to parse the actual sources at some point. I might just miss something but I though we are parsing all that stuff now already or is that still opaque (which is ok!) I just wonder if we miss something here....

@@ -505,18 +361,15 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeBoolean(true);
scroll.writeTo(out);
}
out.writeBytesReference(source);
out.writeBytesReference(extraSource);
if (source == null) {
Copy link
Member

Choose a reason for hiding this comment

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

can the source ever be null? I think it shouldn't be optional in readFrom and writeTo

Copy link
Member

Choose a reason for hiding this comment

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

I got confused with the count request, I see that this can be null, but I still wonder if it should? When does it make sense for it to be null? If it wasn't we could drop a lot of null checks around that.

# Conflicts:
#	core/src/main/java/org/elasticsearch/search/SearchService.java
@@ -71,12 +59,8 @@
@Nullable
private String preference;

private BytesReference templateSource;
private Template template;
private SearchSourceBuilder source;
Copy link
Member

Choose a reason for hiding this comment

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

seems like we can make it final now?

Copy link
Member

Choose a reason for hiding this comment

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

oh no we can't, sorry!

} catch (IOException e) {
sb.append("source[_failed_to_convert_], ");
}
if (context.request().source() != null) {
Copy link
Member

Choose a reason for hiding this comment

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

the null check can be dropped maybe?

@javanna
Copy link
Member

javanna commented Oct 15, 2015

we decided with @colings86 to make the source builder not nullable in the SearchRequest, but to do it after we merge this PR to master. I just did a final round and this LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants