Search code examples
javaelasticsearchspring-data-elasticsearchelasticsearch-java-api

Specify Elasticsearch Ingest Pipeline in Spring Data Elasticsearch


I am using the Elasticsearch's 8.x Java API client for indexing documents to Elasticsearch. While indexing, I'm specifying an ingest pipeline to be executed during data ingestion.

public Mono<IndexResponse> addContent(RequestDoc requestDoc) {
        IndexRequest<ContentTransformedModel> indexRequest = IndexRequest.of(request -> request
                .index("test-index")
                .document(requestDoc)
                .pipeline("test-ingest-pipeline"));
        return reactiveElasticsearchClient.index(indexRequest)
                .onErrorResume(IOException.class,
                        e -> Mono.error(new ElasticsearchPublishException(ES_INDEX_INTERNAL_SERVER_ERROR, e)));
    }

I want to move this implementation to Spring data elasticsearch. Is it possible to configure ingest pipelines for indexing documents in Spring data elasticsearch?


Solution

  • Rather than considering about ingest pipeline you can use default.ingest_pipeline in index settings and it will affect each new indexing request. After put this settings, you just need to push the data. https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html#set-default-pipeline

    PUT your_index_name/_settings
    {
      "index.default_pipeline": "your_ingest_pipeline_name"
    }