-
Notifications
You must be signed in to change notification settings - Fork 24.7k
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
Add Get Source API to the HLRC #50885
Merged
martijnvg
merged 5 commits into
elastic:master
from
timoninmaxim:feature/get_source_api
Jan 23, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1689b36
Add Get Source API to the HLRC
timoninmaxim 3c3ed1e
Use GetSourceRequest, GetSourceResponse for GetSource API
timoninmaxim 7e7341c
Add tests for GetSourceRequest, GetSourceResponse
timoninmaxim 4ccf870
Explicit list of imports
timoninmaxim bfa0cd9
fix tests: Use ToXContentObject for mock server response
timoninmaxim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
client/rest-high-level/src/main/java/org/elasticsearch/client/core/GetSourceRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.client.core; | ||
|
||
import org.elasticsearch.client.Validatable; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.search.fetch.subphase.FetchSourceContext; | ||
|
||
import java.io.IOException; | ||
|
||
public final class GetSourceRequest implements Validatable, ToXContentObject { | ||
private String routing; | ||
private String preference; | ||
|
||
private boolean refresh = false; | ||
private boolean realtime = true; | ||
|
||
private FetchSourceContext fetchSourceContext; | ||
|
||
private String index; | ||
private String id; | ||
|
||
public GetSourceRequest(String index, String id) { | ||
this.index = index; | ||
this.id = id; | ||
} | ||
|
||
/** | ||
* Controls the shard routing of the request. Using this value to hash the shard | ||
* and not the id. | ||
*/ | ||
public GetSourceRequest routing(String routing) { | ||
if (routing != null && routing.length() == 0) { | ||
this.routing = null; | ||
} else { | ||
this.routing = routing; | ||
} | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the preference to execute the search. Defaults to randomize across shards. Can be set to | ||
* {@code _local} to prefer local shards or a custom value, which guarantees that the same order | ||
* will be used across different requests. | ||
*/ | ||
public GetSourceRequest preference(String preference) { | ||
this.preference = preference; | ||
return this; | ||
} | ||
|
||
/** | ||
* Should a refresh be executed before this get operation causing the operation to | ||
* return the latest value. Note, heavy get should not set this to {@code true}. Defaults | ||
* to {@code false}. | ||
*/ | ||
public GetSourceRequest refresh(boolean refresh) { | ||
this.refresh = refresh; | ||
return this; | ||
} | ||
|
||
public GetSourceRequest realtime(boolean realtime) { | ||
this.realtime = realtime; | ||
return this; | ||
} | ||
|
||
/** | ||
* Allows setting the {@link FetchSourceContext} for this request, controlling if and how _source should be returned. | ||
* Note, the {@code fetchSource} field of the context must be set to {@code true}. | ||
*/ | ||
|
||
public GetSourceRequest fetchSourceContext(FetchSourceContext context) { | ||
this.fetchSourceContext = context; | ||
return this; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
return null; | ||
} | ||
|
||
public String index() { | ||
return index; | ||
} | ||
|
||
public String id() { | ||
return id; | ||
} | ||
|
||
public String routing() { | ||
return routing; | ||
} | ||
|
||
public String preference() { | ||
return preference; | ||
} | ||
|
||
public boolean refresh() { | ||
return refresh; | ||
} | ||
|
||
public boolean realtime() { | ||
return realtime; | ||
} | ||
|
||
public FetchSourceContext fetchSourceContext() { | ||
return fetchSourceContext; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
client/rest-high-level/src/main/java/org/elasticsearch/client/core/GetSourceResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.client.core; | ||
|
||
import org.elasticsearch.common.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
public final class GetSourceResponse { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There isn't much here, but maybe also add a test for this? You can extend from |
||
|
||
private final Map<String, Object> source; | ||
|
||
public GetSourceResponse(Map<String, Object> source) { | ||
this.source = source; | ||
} | ||
|
||
public static GetSourceResponse fromXContent(XContentParser parser) throws IOException { | ||
return new GetSourceResponse(parser.map()); | ||
} | ||
|
||
public Map<String, Object> getSource() { | ||
return this.source; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return source.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a test for this in
RequestConvertersTests
?