I have a issue: [es/index] failed: [index_not_found_exception] no such index when I write data into datastream using java client 8.5.3

I have a es cluster with three data nodes. I create a data stream: myindex. when I write data into data stream using java client 8.5.3, I met a problem:

co.elastic.clients.elasticsearch._types.ElasticsearchException: [es/index] failed: [index_not_found_exception] no such index [myindex]

	at co.elastic.clients.transport.rest_client.RestClientTransport.getHighLevelResponse(RestClientTransport.java:282)
	at co.elastic.clients.transport.rest_client.RestClientTransport.performRequest(RestClientTransport.java:148)
	at co.elastic.clients.elasticsearch.ElasticsearchClient.index(ElasticsearchClient.java:962)

This problem does not always occur, only occasionally.

my test code is:

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch._types.OpType;
import co.elastic.clients.elasticsearch.core.IndexRequest;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.junit.Test;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class ElasticSearchTest {
    @Test
    public void testDataStream() {
        RestClient restClient = RestClient.builder(
                new HttpHost("mydomain", 80)).build();

        // Create the transport with a Jackson mapper
        ElasticsearchTransport transport = new RestClientTransport(
                restClient, new JacksonJsonpMapper());

        // And create the API client
        ElasticsearchClient esClient = new ElasticsearchClient(transport);
        Map<String, String> document = new HashMap<>();
        document.put("@timestamp", "2022-12-27 15:08:06.131");
        document.put("rt", "123456");
        try {
            esClient.index(IndexRequest.of(item -> item.index("myindex").opType(OpType.Create).document(document)));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

java client maven dep:

<dependency>
            <groupId>co.elastic.clients</groupId>
            <artifactId>elasticsearch-java</artifactId>
            <version>8.5.3</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.13</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.12.3</version>
        </dependency>
        <dependency>
            <groupId>jakarta.json</groupId>
            <artifactId>jakarta.json-api</artifactId>
            <version>2.0.1</version>
        </dependency>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.