Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

`rebuild()` of bulk operations (`IndexOperation`, `CreateOperation`, `UpdateOperation`) drops most fields

Aperta
#1,353 1 commento 0 reazioni 1 assegnatario Vedi su GitHub

@l-trotta ci sta già lavorando.

Dal 15/10/2026.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
50/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
elasticsearch, java
Ambito
api

Direzione di ricerca

The bug is in the private Builder(IndexOperation), Builder(CreateOperation) and Builder(UpdateOperation) constructors, which copy too few fields. Those classes inherit from BulkOperationBase and WriteOperation, and the reproducer in the issue shows which properties go missing. The likely cause is the code generator, so check whether the fix belongs in the generated sources or in the generator. Done means op.rebuild().build() equals op for all three operation types, with the builder typed as Builder<TDocument>.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Area: Generator Category: Bug
Java API client version

9.5.4 (also current main)

Java version

25

Elasticsearch Version

9.5.4

Problem description

(full disclosure: analysis by copilot)

rebuild() should return a builder "initialized with field values of this instance". For the bulk operation classes it doesn't: most fields are lost.

Expected: op.rebuild().build() is equal to op.

Actual:

  • IndexOperation and CreateOperation: the private Builder(IndexOperation<TDocument> instance) / Builder(CreateOperation<TDocument> instance) constructors are empty. Nothing is copied:

    • fields inherited from BulkOperationBase: id, index, routing, ifSeqNo, ifPrimaryTerm, version, versionType;
    • fields inherited from WriteOperation: pipeline, requireAlias, dynamicTemplates;
    • their own fields: document and tDocumentSerializer.

    Because document is required, rebuild().build() throws a MissingRequiredPropertyException. If you set a new document first (for example .document(binaryData)), it builds without errors, but without _id, _index, routing and so on.

  • UpdateOperation: only requireAlias and retryOnConflict are copied. The inherited BulkOperationBase fields, action, binaryAction and the serializers are lost.

This looks like a code generator problem. Fields inherited from a generated base class are never copied, and neither are fields of the generic type parameter. Request classes without a base class, such as IndexRequest, copy their fields correctly.

Reproducer:

IndexOperation<Map<String, Object>> op = IndexOperation.of(b -> b
    .index("my-index")
    .id("1")
    .routing("r1")
    .ifSeqNo(5L)
    .ifPrimaryTerm(1L)
    .pipeline("my-pipeline")
    .document(Map.of("field", "value")));

// throws MissingRequiredPropertyException: Missing required property 'IndexOperation.document'
op.rebuild().build();

// builds without errors, but all values are lost
IndexOperation<?> copy = op.rebuild().document(Map.of("field", "value")).build();
System.out.println(copy.index());   // null, expected "my-index"
System.out.println(copy.id());      // null, expected "1"
System.out.println(copy.routing()); // null, expected "r1"
System.out.println(copy.pipeline()); // null, expected "my-pipeline"

CreateOperation behaves the same. For UpdateOperation, rebuild().build() does not throw, but only requireAlias and retryOnConflict are kept:

UpdateOperation<Object, Object> op = UpdateOperation.of(b -> b
    .index("my-index")
    .id("1")
    .routing("r1")
    .retryOnConflict(3)
    .action(a -> a.docAsUpsert(true)));

UpdateOperation<?, ?> copy = op.rebuild().build();
System.out.println(copy.index());           // null, expected "my-index"
System.out.println(copy.id());              // null, expected "1"
System.out.println(copy.routing());         // null, expected "r1"
System.out.println(copy.retryOnConflict()); // 3
System.out.println(copy.action());          // null

Context: I hit this in Spring Data Elasticsearch. Like the client's own BulkIngester, it needs to replace the document of an operation with a pre-serialized BinaryData so that it can measure its size. The obvious way is op.rebuild().document(binaryData).build(), but that silently drops _id and _index. So we copy all properties by hand, as IngesterOperation.copyIndexProperties() / copyBaseProperties() do.
see https://github.com/spring-projects/spring-data-elasticsearch/pull/3357

Note: rebuild() also returns the raw type Builder instead of Builder<TDocument>, so callers get unchecked warnings.

Lingua principale
Java
Stelle
525
Fork
299
Merge medio
13h 9m
PR unite (30g)
5

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di elastic/elasticsearch-java

Tutte le issue di elastic/elasticsearch-java

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.