{"record":{"id":"608a122b100e71e7","repo":"quarkusio/quarkus","slug":"the-indexing-operation-encountered-errors","errorCode":null,"errorMessage":"The indexing operation encountered errors.","messagePattern":"The indexing operation encountered errors\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"integration-tests/elasticsearch-java-client/src/main/java/io/quarkus/it/elasticsearch/java/FruitService.java","lineNumber":88,"sourceCode":"        }\n        SearchResponse<Fruit> searchResponse = client.search(searchRequest, Fruit.class);\n        HitsMetadata<Fruit> hits = searchResponse.hits();\n        return hits.hits().stream().map(Hit::source).collect(Collectors.toList());\n    }\n\n    public void index(List<Fruit> list) throws IOException {\n\n        BulkRequest.Builder br = new BulkRequest.Builder();\n\n        for (var fruit : list) {\n            br.operations(op -> op\n                    .index(idx -> idx.index(\"fruits\").id(fruit.id).document(fruit)));\n        }\n\n        BulkResponse result = client.bulk(br.build());\n\n        if (result.errors()) {\n            throw new RuntimeException(\"The indexing operation encountered errors.\");\n        }\n    }\n\n    public void delete(List<String> list) throws IOException {\n\n        BulkRequest.Builder br = new BulkRequest.Builder();\n\n        for (var id : list) {\n            br.operations(op -> op.delete(idx -> idx.index(\"fruits\").id(id)));\n        }\n\n        BulkResponse result = client.bulk(br.build());\n\n        if (result.errors()) {\n            throw new RuntimeException(\"The indexing operation encountered errors.\");\n        }\n    }\n}","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/elasticsearch-java-client/src/main/java/io/quarkus/it/elasticsearch/java/FruitService.java#L70-L106","documentation":"Thrown by FruitService.index after executing an Elasticsearch bulk request: the co-eloquent Java client's BulkResponse.errors() flag is true, meaning at least one individual bulk item failed to index. The service deliberately throws a generic RuntimeException instead of surfacing per-item details.","triggerScenarios":"client.bulk(...) where any document (e.g. a fruit with duplicate id conflicting mapping or invalid document) fails; index 'fruits' having a mapping that rejects a field value; shard unavailability on the Elasticsearch node.","commonSituations":"Elasticsearch Dev Service not fully ready / wrong port; mapping conflicts after schema changes; version mismatch between elasticsearch-java client and server; cluster health red during tests.","solutions":["Inspect result.items() per-item failure reasons and log/fix the failing document before retrying.","Verify the 'fruits' index mapping matches the Fruit document fields (delete/recreate the index if stale).","Ensure the Elasticsearch container/Dev Service is healthy and reachable on the configured host/port.","Align the elasticsearch-java client version with the server version."],"exampleFix":"// before\nif (result.errors()) { throw new RuntimeException(\"The indexing operation encountered errors.\"); }\n// after\nif (result.errors()) {\n    result.items().stream().filter(i -> i.error() != null)\n        .forEach(i -> Log.error(\"Bulk item failed: \" + i.id() + \" -> \" + i.error().reason()));\n    throw new RuntimeException(\"The indexing operation encountered errors.\");\n}","handlingStrategy":"try-catch","validationCode":"// ensure cluster is healthy before bulk\ncom.fasterxml.jackson.databind.JsonNode health = restClient.performRequest(new Request(\"GET\", \"/_cluster/health\"));\n// require status != red and index exists","typeGuard":"null","tryCatchPattern":"try {\n    fruitService.index(fruits);\n} catch (RuntimeException e) {\n    if (e.getMessage().contains(\"The indexing operation encountered errors\")) {\n        log.error(\"Bulk indexing partially failed; inspect per-item errors and retry failed ids\");\n    } else throw e;\n}","preventionTips":["Wait for Elasticsearch readiness (cluster health green/yellow) before bulk operations.","Recreate the 'fruits' index when the Fruit schema changes.","Keep elasticsearch-java client version aligned with the server.","Log per-item bulk errors instead of only the aggregate flag."],"tags":["elasticsearch","bulk-indexing","java-client"],"backgroundTag":"bulk-index-failed","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}