org.elasticsearch.client.action.index
Class IndexRequestBuilder

java.lang.Object
  extended by org.elasticsearch.client.action.support.BaseRequestBuilder<IndexRequest,IndexResponse>
      extended by org.elasticsearch.client.action.index.IndexRequestBuilder
All Implemented Interfaces:
RequestBuilder<IndexRequest,IndexResponse>

public class IndexRequestBuilder
extends BaseRequestBuilder<IndexRequest,IndexResponse>

An index document action request builder.


Field Summary
 
Fields inherited from class org.elasticsearch.client.action.support.BaseRequestBuilder
client, request
 
Constructor Summary
IndexRequestBuilder(Client client, java.lang.String index)
           
 
Method Summary
protected  void doExecute(ActionListener<IndexResponse> listener)
           
 IndexRequestBuilder setConsistencyLevel(WriteConsistencyLevel consistencyLevel)
          Sets the consistency level.
 IndexRequestBuilder setContentType(XContentType contentType)
          The content type that will be used to generate a document from user provided objects (like Map).
 IndexRequestBuilder setCreate(boolean create)
          Set to true to force this index to use IndexRequest.OpType.CREATE.
 IndexRequestBuilder setId(java.lang.String id)
          Sets the id to index the document under.
 IndexRequestBuilder setIndex(java.lang.String index)
          Sets the index to index the document to.
 IndexRequestBuilder setListenerThreaded(boolean listenerThreaded)
          Should the listener be called on a separate thread if needed.
 IndexRequestBuilder setOperationThreaded(boolean operationThreaded)
          Controls if the operation will be executed on a separate thread when executed locally.
 IndexRequestBuilder setOpType(IndexRequest.OpType opType)
          Sets the type of operation to perform.
 IndexRequestBuilder setOpType(java.lang.String opType)
          Sets a string representation of the setOpType(org.elasticsearch.action.index.IndexRequest.OpType).
 IndexRequestBuilder setParent(java.lang.String parent)
          Sets the parent id of this document.
 IndexRequestBuilder setPercolate(java.lang.String percolate)
          Causes the index request document to be percolated.
 IndexRequestBuilder setRefresh(boolean refresh)
          Should a refresh be executed post this index operation causing the operation to be searchable.
 IndexRequestBuilder setReplicationType(ReplicationType replicationType)
          Set the replication type for this operation.
 IndexRequestBuilder setReplicationType(java.lang.String replicationType)
          Set the replication type for this operation.
 IndexRequestBuilder setRouting(java.lang.String routing)
          Controls the shard routing of the request.
 IndexRequestBuilder setSource(byte[] source)
          Sets the document to index in bytes form.
 IndexRequestBuilder setSource(byte[] source, int offset, int length)
          Sets the document to index in bytes form (assumed to be safe to be used from different threads).
 IndexRequestBuilder setSource(byte[] source, int offset, int length, boolean unsafe)
          Sets the document to index in bytes form.
 IndexRequestBuilder setSource(java.util.Map<java.lang.String,java.lang.Object> source)
          Index the Map as a JSON.
 IndexRequestBuilder setSource(java.util.Map<java.lang.String,java.lang.Object> source, XContentType contentType)
          Index the Map as the provided content type.
 IndexRequestBuilder setSource(java.lang.String source)
          Sets the document source to index.
 IndexRequestBuilder setSource(java.lang.String field1, java.lang.Object value1)
          Constructs a simple document with a field and a value.
 IndexRequestBuilder setSource(java.lang.String field1, java.lang.Object value1, java.lang.String field2, java.lang.Object value2)
          Constructs a simple document with a field and value pairs.
 IndexRequestBuilder setSource(java.lang.String field1, java.lang.Object value1, java.lang.String field2, java.lang.Object value2, java.lang.String field3, java.lang.Object value3)
          Constructs a simple document with a field and value pairs.
 IndexRequestBuilder setSource(java.lang.String field1, java.lang.Object value1, java.lang.String field2, java.lang.Object value2, java.lang.String field3, java.lang.Object value3, java.lang.String field4, java.lang.Object value4)
          Constructs a simple document with a field and value pairs.
 IndexRequestBuilder setSource(XContentBuilder sourceBuilder)
          Sets the content source to index.
 IndexRequestBuilder setTimeout(java.lang.String timeout)
          A timeout to wait if the index operation can't be performed immediately.
 IndexRequestBuilder setTimeout(TimeValue timeout)
          A timeout to wait if the index operation can't be performed immediately.
 IndexRequestBuilder setType(java.lang.String type)
          Sets the type to index the document to.
 IndexRequestBuilder setVersion(long version)
          Sets the version, which will cause the index operation to only be performed if a matching version exists and no changes happened on the doc since then.
 IndexRequestBuilder setVersionType(VersionType versionType)
          Sets the versioning type.
 
Methods inherited from class org.elasticsearch.client.action.support.BaseRequestBuilder
execute, execute, request
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IndexRequestBuilder

public IndexRequestBuilder(Client client,
                           @Nullable
                           java.lang.String index)
Method Detail

setIndex

public IndexRequestBuilder setIndex(java.lang.String index)
Sets the index to index the document to.


setType

public IndexRequestBuilder setType(java.lang.String type)
Sets the type to index the document to.


setId

public IndexRequestBuilder setId(java.lang.String id)
Sets the id to index the document under. Optional, and if not set, one will be automatically generated.


setRouting

public IndexRequestBuilder setRouting(java.lang.String routing)
Controls the shard routing of the request. Using this value to hash the shard and not the id.


setParent

public IndexRequestBuilder setParent(java.lang.String parent)
Sets the parent id of this document. If routing is not set, automatically set it as the routing as well.


setSource

public IndexRequestBuilder setSource(java.util.Map<java.lang.String,java.lang.Object> source)
Index the Map as a JSON.

Parameters:
source - The map to index

setSource

public IndexRequestBuilder setSource(java.util.Map<java.lang.String,java.lang.Object> source,
                                     XContentType contentType)
Index the Map as the provided content type.

Parameters:
source - The map to index

setSource

public IndexRequestBuilder setSource(java.lang.String source)
Sets the document source to index.

Note, its preferable to either set it using setSource(org.elasticsearch.common.xcontent.XContentBuilder) or using the setSource(byte[]).


setSource

public IndexRequestBuilder setSource(XContentBuilder sourceBuilder)
Sets the content source to index.


setSource

public IndexRequestBuilder setSource(byte[] source)
Sets the document to index in bytes form.


setSource

public IndexRequestBuilder setSource(byte[] source,
                                     int offset,
                                     int length)
Sets the document to index in bytes form (assumed to be safe to be used from different threads).

Parameters:
source - The source to index
offset - The offset in the byte array
length - The length of the data

setSource

public IndexRequestBuilder setSource(byte[] source,
                                     int offset,
                                     int length,
                                     boolean unsafe)
Sets the document to index in bytes form.

Parameters:
source - The source to index
offset - The offset in the byte array
length - The length of the data
unsafe - Is the byte array safe to be used form a different thread

setSource

public IndexRequestBuilder setSource(java.lang.String field1,
                                     java.lang.Object value1)
Constructs a simple document with a field and a value.


setSource

public IndexRequestBuilder setSource(java.lang.String field1,
                                     java.lang.Object value1,
                                     java.lang.String field2,
                                     java.lang.Object value2)
Constructs a simple document with a field and value pairs.


setSource

public IndexRequestBuilder setSource(java.lang.String field1,
                                     java.lang.Object value1,
                                     java.lang.String field2,
                                     java.lang.Object value2,
                                     java.lang.String field3,
                                     java.lang.Object value3)
Constructs a simple document with a field and value pairs.


setSource

public IndexRequestBuilder setSource(java.lang.String field1,
                                     java.lang.Object value1,
                                     java.lang.String field2,
                                     java.lang.Object value2,
                                     java.lang.String field3,
                                     java.lang.Object value3,
                                     java.lang.String field4,
                                     java.lang.Object value4)
Constructs a simple document with a field and value pairs.


setContentType

public IndexRequestBuilder setContentType(XContentType contentType)
The content type that will be used to generate a document from user provided objects (like Map).


setTimeout

public IndexRequestBuilder setTimeout(TimeValue timeout)
A timeout to wait if the index operation can't be performed immediately. Defaults to 1m.


setTimeout

public IndexRequestBuilder setTimeout(java.lang.String timeout)
A timeout to wait if the index operation can't be performed immediately. Defaults to 1m.


setOpType

public IndexRequestBuilder setOpType(IndexRequest.OpType opType)
Sets the type of operation to perform.


setOpType

public IndexRequestBuilder setOpType(java.lang.String opType)
Sets a string representation of the setOpType(org.elasticsearch.action.index.IndexRequest.OpType). Can be either "index" or "create".


setCreate

public IndexRequestBuilder setCreate(boolean create)
Set to true to force this index to use IndexRequest.OpType.CREATE.


setRefresh

public IndexRequestBuilder setRefresh(boolean refresh)
Should a refresh be executed post this index operation causing the operation to be searchable. Note, heavy indexing should not set this to true. Defaults to false.


setReplicationType

public IndexRequestBuilder setReplicationType(ReplicationType replicationType)
Set the replication type for this operation.


setConsistencyLevel

public IndexRequestBuilder setConsistencyLevel(WriteConsistencyLevel consistencyLevel)
Sets the consistency level. Defaults to WriteConsistencyLevel.DEFAULT.


setReplicationType

public IndexRequestBuilder setReplicationType(java.lang.String replicationType)
Set the replication type for this operation.


setVersion

public IndexRequestBuilder setVersion(long version)
Sets the version, which will cause the index operation to only be performed if a matching version exists and no changes happened on the doc since then.


setVersionType

public IndexRequestBuilder setVersionType(VersionType versionType)
Sets the versioning type. Defaults to VersionType.INTERNAL.


setPercolate

public IndexRequestBuilder setPercolate(java.lang.String percolate)
Causes the index request document to be percolated. The parameter is the percolate query to use to reduce the percolated queries that are going to run against this doc. Can be set to * to indicate that all percolate queries should be run.


setListenerThreaded

public IndexRequestBuilder setListenerThreaded(boolean listenerThreaded)
Should the listener be called on a separate thread if needed.


setOperationThreaded

public IndexRequestBuilder setOperationThreaded(boolean operationThreaded)
Controls if the operation will be executed on a separate thread when executed locally. Defaults to true when running in embedded mode.


doExecute

protected void doExecute(ActionListener<IndexResponse> listener)
Specified by:
doExecute in class BaseRequestBuilder<IndexRequest,IndexResponse>