Class IndexRequestBuilder

All Implemented Interfaces:
WriteRequestBuilder<IndexRequestBuilder>

An index document action request builder.
  • Constructor Details

  • Method Details

    • 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.
    • setSource

      public IndexRequestBuilder setSource(BytesReference source, org.elasticsearch.common.xcontent.XContentType xContentType)
      Sets the source.
    • setSource

      public IndexRequestBuilder setSource(Map<String,?> source)
      Index the Map as a JSON.
      Parameters:
      source - The map to index
    • setSource

      public IndexRequestBuilder setSource(Map<String,?> source, org.elasticsearch.common.xcontent.XContentType contentType)
      Index the Map as the provided content type.
      Parameters:
      source - The map to index
    • setSource

      public IndexRequestBuilder setSource(String source, org.elasticsearch.common.xcontent.XContentType xContentType)
      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[], XContentType).

    • setSource

      public IndexRequestBuilder setSource(org.elasticsearch.common.xcontent.XContentBuilder sourceBuilder)
      Sets the content source to index.
    • setSource

      public IndexRequestBuilder setSource(byte[] source, org.elasticsearch.common.xcontent.XContentType xContentType)
      Sets the document to index in bytes form.
    • setSource

      public IndexRequestBuilder setSource(byte[] source, int offset, int length, org.elasticsearch.common.xcontent.XContentType xContentType)
      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
      xContentType - The type/format of the source
    • setSource

      public IndexRequestBuilder setSource(Object... source)
      Constructs a simple document with a field name and value pairs.

      Note: the number of objects passed to this method must be an even number. Also the first argument in each pair (the field name) must have a valid String representation.

    • setSource

      public IndexRequestBuilder setSource(org.elasticsearch.common.xcontent.XContentType xContentType, Object... source)
      Constructs a simple document with a field name and value pairs.

      Note: the number of objects passed as varargs to this method must be an even number. Also the first argument in each pair (the field name) must have a valid String representation.

    • setOpType

      public IndexRequestBuilder setOpType(DocWriteRequest.OpType opType)
      Sets the type of operation to perform.
    • setCreate

      public IndexRequestBuilder setCreate(boolean create)
      Set to true to force this index to use DocWriteRequest.OpType.CREATE.
    • 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.
    • setIfSeqNo

      public IndexRequestBuilder setIfSeqNo(long seqNo)
      only perform this indexing request if the document was last modification was assigned the given sequence number. Must be used in combination with setIfPrimaryTerm(long) If the document last modification was assigned a different sequence number a VersionConflictEngineException will be thrown.
    • setIfPrimaryTerm

      public IndexRequestBuilder setIfPrimaryTerm(long term)
      only perform this indexing request if the document was last modification was assigned the given primary term. Must be used in combination with setIfSeqNo(long) If the document last modification was assigned a different term a VersionConflictEngineException will be thrown.
    • setPipeline

      public IndexRequestBuilder setPipeline(String pipeline)
      Sets the ingest pipeline to be executed before indexing the document
    • setRequireAlias

      public IndexRequestBuilder setRequireAlias(boolean requireAlias)
      Sets the require_alias flag