Class GetRequest

All Implemented Interfaces:
IndicesRequest, RealtimeRequest, Writeable, TaskAwareRequest

public class GetRequest
extends SingleShardRequest<GetRequest>
implements RealtimeRequest
A request to get a document (its source) from an index based on its id. Best created using Requests.getRequest(String).

The operation requires the SingleShardRequest.index(), type(String) and id(String) to be set.

See Also:
GetResponse, Requests.getRequest(String), Client.get(GetRequest)
  • Constructor Details

    • GetRequest

      public GetRequest()
    • GetRequest

      public GetRequest​(java.lang.String index)
      Constructs a new get request against the specified index. The id(String) must also be set.
    • GetRequest

      @Deprecated public GetRequest​(java.lang.String index, java.lang.String type, java.lang.String id)
      Deprecated.
      Types are in the process of being removed, use GetRequest(java.lang.String,java.lang.String) instead.
      Constructs a new get request against the specified index with the type and id.
      Parameters:
      index - The index to get the document from
      type - The type of the document
      id - The id of the document
    • GetRequest

      public GetRequest​(java.lang.String index, java.lang.String id)
      Constructs a new get request against the specified index and document ID.
      Parameters:
      index - The index to get the document from
      id - The id of the document
  • Method Details

    • validate

      Specified by:
      validate in class ActionRequest
    • type

      @Deprecated public GetRequest type​(@Nullable java.lang.String type)
      Deprecated.
      Types are in the process of being removed.
      Sets the type of the document to fetch.
    • id

      public GetRequest id​(java.lang.String id)
      Sets the id of the document to fetch.
    • 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 or a custom value, which guarantees that the same order will be used across different requests.
    • type

      @Deprecated public java.lang.String type()
      Deprecated.
      Types are in the process of being removed.
    • 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 the FetchSourceContext 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 to true. Defaults to false.
    • refresh

      public boolean refresh()
    • realtime

      public boolean realtime()
    • realtime

      public GetRequest realtime​(boolean realtime)
      Specified by:
      realtime in interface RealtimeRequest
      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 to VersionType.INTERNAL.
    • versionType

      public VersionType versionType()
    • writeTo

      public void writeTo​(StreamOutput out) throws java.io.IOException
      Description copied from interface: Writeable
      Write this into the StreamOutput.
      Specified by:
      writeTo in interface Writeable
      Overrides:
      writeTo in class SingleShardRequest<GetRequest>
      Throws:
      java.io.IOException
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object