org.elasticsearch.action.index
Class IndexRequestBuilder

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

public class IndexRequestBuilder
extends BaseRequestBuilder<IndexRequest,IndexResponse>

An index document action request builder.


Field Summary
 
Fields inherited from class org.elasticsearch.action.support.BaseRequestBuilder
client, request
 
Constructor Summary
IndexRequestBuilder(Client client)
           
IndexRequestBuilder(Client client, 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(String id)
          Sets the id to index the document under.
 IndexRequestBuilder setIndex(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(String opType)
          Sets a string representation of the setOpType(org.elasticsearch.action.index.IndexRequest.OpType).
 IndexRequestBuilder setParent(String parent)
          Sets the parent id of this document.
 IndexRequestBuilder setPercolate(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(String replicationType)
          Set the replication type for this operation.
 IndexRequestBuilder setRouting(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(BytesReference source)
          Sets the source.
 IndexRequestBuilder setSource(BytesReference source, boolean unsafe)
          Sets the source.
 IndexRequestBuilder setSource(Map<String,Object> source)
          Index the Map as a JSON.
 IndexRequestBuilder setSource(Map<String,Object> source, XContentType contentType)
          Index the Map as the provided content type.
 IndexRequestBuilder setSource(String source)
          Sets the document source to index.
 IndexRequestBuilder setSource(String field1, Object value1)
          Constructs a simple document with a field and a value.
 IndexRequestBuilder setSource(String field1, Object value1, String field2, Object value2)
          Constructs a simple document with a field and value pairs.
 IndexRequestBuilder setSource(String field1, Object value1, String field2, Object value2, String field3, Object value3)
          Constructs a simple document with a field and value pairs.
 IndexRequestBuilder setSource(String field1, Object value1, String field2, Object value2, String field3, Object value3, String field4, Object value4)
          Constructs a simple document with a field and value pairs.
 IndexRequestBuilder setSource(XContentBuilder sourceBuilder)
          Sets the content source to index.
 IndexRequestBuilder setTimeout(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 setTimestamp(String timestamp)
          Sets the timestamp either as millis since the epoch, or, in the configured date format.
 IndexRequestBuilder setTTL(long ttl)
           
 IndexRequestBuilder setType(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.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)

IndexRequestBuilder

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

setIndex

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


setType

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


setId

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


setRouting

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


setParent

public IndexRequestBuilder setParent(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(BytesReference source,
                                     boolean unsafe)
Sets the source.


setSource

public IndexRequestBuilder setSource(BytesReference source)
Sets the source.


setSource

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

Parameters:
source - The map to index

setSource

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

Parameters:
source - The map to index

setSource

public IndexRequestBuilder setSource(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(String field1,
                                     Object value1)
Constructs a simple document with a field and a value.


setSource

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


setSource

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


setSource

public IndexRequestBuilder setSource(String field1,
                                     Object value1,
                                     String field2,
                                     Object value2,
                                     String field3,
                                     Object value3,
                                     String field4,
                                     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(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(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(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(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.


setTimestamp

public IndexRequestBuilder setTimestamp(String timestamp)
Sets the timestamp either as millis since the epoch, or, in the configured date format.


setTTL

public IndexRequestBuilder setTTL(long ttl)

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>


Copyright © 2009-2012. All Rights Reserved.