Package org.elasticsearch.action.get
Class GetRequest
- java.lang.Object
-
- All Implemented Interfaces:
IndicesRequest
,RealtimeRequest
,Streamable
,Writeable
,TaskAwareRequest
public class GetRequest extends SingleShardRequest<GetRequest> implements RealtimeRequest
A request to get a document (its source) from an index based on its type (optional) and id. Best created usingRequests.getRequest(String)
.The operation requires the
SingleShardRequest.index()
,type(String)
andid(String)
to be set.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.elasticsearch.transport.TransportRequest
TransportRequest.Empty
-
Nested classes/interfaces inherited from interface org.elasticsearch.action.IndicesRequest
IndicesRequest.Replaceable
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
-
Field Summary
-
Fields inherited from class org.elasticsearch.action.support.single.shard.SingleShardRequest
index, INDICES_OPTIONS
-
-
Constructor Summary
Constructors Constructor Description GetRequest()
GetRequest(java.lang.String index)
Constructs a new get request against the specified index.GetRequest(java.lang.String index, java.lang.String type, java.lang.String id)
Constructs a new get request against the specified index with the type and id.
-
Method Summary
Modifier and Type Method Description FetchSourceContext
fetchSourceContext()
GetRequest
fetchSourceContext(FetchSourceContext context)
Allows setting theFetchSourceContext
for this request, controlling if and how _source should be returned.java.lang.String
id()
GetRequest
id(java.lang.String id)
Sets the id of the document to fetch.java.lang.String
parent()
GetRequest
parent(java.lang.String parent)
Sets the parent id of this document.java.lang.String
preference()
GetRequest
preference(java.lang.String preference)
Sets the preference to execute the search.void
readFrom(StreamInput in)
Set this object's fields from a StreamInput.boolean
realtime()
GetRequest
realtime(boolean realtime)
boolean
refresh()
GetRequest
refresh(boolean refresh)
Should a refresh be executed before this get operation causing the operation to return the latest value.java.lang.String
routing()
GetRequest
routing(java.lang.String routing)
Controls the shard routing of the request.java.lang.String[]
storedFields()
Explicitly specify the stored fields that will be returned.GetRequest
storedFields(java.lang.String... fields)
Explicitly specify the stored fields that will be returned.java.lang.String
toString()
java.lang.String
type()
GetRequest
type(java.lang.String type)
Sets the type of the document to fetch.ActionRequestValidationException
validate()
long
version()
Sets the version, which will cause the get operation to only be performed if a matching version exists and no changes happened on the doc since then.GetRequest
version(long version)
VersionType
versionType()
GetRequest
versionType(VersionType versionType)
Sets the versioning type.void
writeTo(StreamOutput out)
Write this object's fields to a StreamOutput.-
Methods inherited from class org.elasticsearch.action.support.single.shard.SingleShardRequest
index, index, indices, indicesOptions, validateNonNullIndex
-
Methods inherited from class org.elasticsearch.action.ActionRequest
getShouldStoreResult
-
Methods inherited from class org.elasticsearch.transport.TransportRequest
getParentTask, setParentTask
-
Methods inherited from class org.elasticsearch.transport.TransportMessage
remoteAddress, remoteAddress
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.tasks.TaskAwareRequest
createTask, getDescription, setParentTask
-
-
-
-
Constructor Detail
-
GetRequest
public GetRequest()
-
GetRequest
public GetRequest(java.lang.String index)
Constructs a new get request against the specified index. Thetype(String)
andid(String)
must be set.
-
GetRequest
public GetRequest(java.lang.String index, java.lang.String type, java.lang.String id)
Constructs a new get request against the specified index with the type and id.- Parameters:
index
- The index to get the document fromtype
- The type of the documentid
- The id of the document
-
-
Method Detail
-
validate
public ActionRequestValidationException validate()
- Specified by:
validate
in classActionRequest
-
type
public GetRequest type(@Nullable java.lang.String type)
Sets the type of the document to fetch.
-
id
public GetRequest id(java.lang.String id)
Sets the id of the document to fetch.
-
parent
public java.lang.String parent()
- Returns:
- The parent for this request.
-
parent
public GetRequest parent(java.lang.String parent)
Sets the parent id of this document.
-
routing
public GetRequest routing(java.lang.String routing)
Controls the shard routing of the request. Using this value to hash the shard and not the id.
-
preference
public GetRequest preference(java.lang.String preference)
Sets the preference to execute the search. Defaults to randomize across shards. Can be set to_local
to prefer local shards,_primary
to execute only on primary shards, or a custom value, which guarantees that the same order will be used across different requests.
-
type
public java.lang.String type()
-
id
public java.lang.String id()
-
routing
public java.lang.String routing()
-
preference
public java.lang.String preference()
-
fetchSourceContext
public GetRequest fetchSourceContext(FetchSourceContext context)
Allows setting theFetchSourceContext
for this request, controlling if and how _source should be returned.
-
fetchSourceContext
public FetchSourceContext fetchSourceContext()
-
storedFields
public GetRequest storedFields(java.lang.String... fields)
Explicitly specify the stored fields that will be returned. By default, the_source
field will be returned.
-
storedFields
public java.lang.String[] storedFields()
Explicitly specify the stored fields that will be returned. By default, the_source
field will be returned.
-
refresh
public GetRequest refresh(boolean refresh)
Should a refresh be executed before this get operation causing the operation to return the latest value. Note, heavy get should not set this totrue
. Defaults tofalse
.
-
refresh
public boolean refresh()
-
realtime
public boolean realtime()
-
realtime
public GetRequest realtime(boolean realtime)
- Specified by:
realtime
in interfaceRealtimeRequest
- Parameters:
realtime
- Controls whether this request should be realtime by reading from the translog.
-
version
public long version()
Sets the version, which will cause the get operation to only be performed if a matching version exists and no changes happened on the doc since then.
-
version
public GetRequest version(long version)
-
versionType
public GetRequest versionType(VersionType versionType)
Sets the versioning type. Defaults toVersionType.INTERNAL
.
-
versionType
public VersionType versionType()
-
readFrom
public void readFrom(StreamInput in) throws java.io.IOException
Description copied from interface:Streamable
Set this object's fields from a StreamInput.- Specified by:
readFrom
in interfaceStreamable
- Overrides:
readFrom
in classSingleShardRequest<GetRequest>
- Throws:
java.io.IOException
-
writeTo
public void writeTo(StreamOutput out) throws java.io.IOException
Description copied from interface:Streamable
Write this object's fields to a StreamOutput.- Specified by:
writeTo
in interfaceStreamable
- Specified by:
writeTo
in interfaceWriteable
- Overrides:
writeTo
in classSingleShardRequest<GetRequest>
- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-