Elasticsearch 8 Java Client ResponseException status line [HTTP/1.1 404 Not Found] {"statusCode":404,"error":"Not Found","message":"Not Found"}

Hello,

this is Michael from germany and i am reaching out to you because i have to finish my master thesis before 31.10.2022.

I had working code in july 2022 which i didn't touch since then. I used the online 2 weeks trial vom elastic.co to connect and do my stuff. Now i want to execute the code again on a new 2 weeks trial but i am facing an error, which i can't solve.
What happened in the meanwhile:
a) in july i used version 8.2.0 of the software while meanwhile Elasticsearch company released
version 8.4.0 of their software.
b) i changed password in the code, because i have a new 2 weeks trial now.

Here are some short example codes which all fail (actually my real code is bigger but these are small examples). Only the code after the line // "productive code" changes

Creating an index:

package Kapselung;

import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.rest_client.RestClientTransport;

public class create_index {

	public static void main(String[] args) {
		String username = "elastic";
		String password = "JotkB5QY5v9IN0qRtvf6d5dL";
		String host = "gattinger-fourth.kb.us-central1.gcp.cloud.es.io";
		int port = 9243;
		RestClient restClient;
		ElasticsearchClient ESClient;

		// https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/connecting.html
		// https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/_basic_authentication.html
		final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
		credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
		HttpClientConfigCallback httpClientConfigCallback = new HttpClientConfigCallback() {
			@Override
			public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
				httpClientBuilder.disableAuthCaching();
				return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
			}
		};

		// Create the low-level client
		RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(host, port, "https"));
		restClientBuilder.setHttpClientConfigCallback(httpClientConfigCallback);
		restClient = restClientBuilder.build();

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

		// "productive code"
		try {
			ESClient.indices().create(c -> c.index("products100"));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}

Failure is:

co.elastic.clients.transport.TransportException: [es/indices.create] Failed to decode error response
	at co.elastic.clients.transport.rest_client.RestClientTransport.getHighLevelResponse(RestClientTransport.java:290)
	at co.elastic.clients.transport.rest_client.RestClientTransport.performRequest(RestClientTransport.java:147)
	at co.elastic.clients.elasticsearch.indices.ElasticsearchIndicesClient.create(ElasticsearchIndicesClient.java:266)
	at co.elastic.clients.elasticsearch.indices.ElasticsearchIndicesClient.create(ElasticsearchIndicesClient.java:282)
	at Kapselung.create_index.main(create_index.java:51)
Caused by: org.elasticsearch.client.ResponseException: method [PUT], host [https://gattinger-fourth.kb.us-central1.gcp.cloud.es.io:9243], URI [/products100], status line [HTTP/1.1 404 Not Found]

	... 5 more

Or posting a document:

package Kapselung;

import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback;

import com.fasterxml.jackson.databind.ObjectMapper;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.rest_client.RestClientTransport;

public class post_document {

	public static void main(String[] args) {
		String username = "elastic";
		String password = "JotkB5QY5v9IN0qRtvf6d5dL";
		String host = "gattinger-fourth.kb.us-central1.gcp.cloud.es.io";
		int port = 9243;
		RestClient restClient;
		ElasticsearchClient ESClient;

		// https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/connecting.html
		// https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/_basic_authentication.html
		final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
		credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
		HttpClientConfigCallback httpClientConfigCallback = new HttpClientConfigCallback() {
			@Override
			public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
				httpClientBuilder.disableAuthCaching();
				return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
			}
		};

		// Create the low-level client
		RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(host, port, "https"));
		restClientBuilder.setHttpClientConfigCallback(httpClientConfigCallback);
		restClient = restClientBuilder.build();

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

		// "productive code"
		try {
			Request request = new Request("POST", "/products100/_doc");
			String document = "{\"sku\": \"21847816\",\"name\": \"Rasierapparat\",\"price\": 23.99}";
			ObjectMapper mapper = new ObjectMapper(); // Jackson Json
			request.setJsonEntity(mapper.writeValueAsString(document));
			Response response = restClient.performRequest(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}

failure:

org.elasticsearch.client.ResponseException: method [POST], host [https://gattinger-fourth.kb.us-central1.gcp.cloud.es.io:9243], URI [/products100/_doc], status line [HTTP/1.1 404 Not Found]
{"statusCode":404,"error":"Not Found","message":"Not Found"}
	at org.elasticsearch.client.RestClient.convertResponse(RestClient.java:346)
	at org.elasticsearch.client.RestClient.performRequest(RestClient.java:312)
	at org.elasticsearch.client.RestClient.performRequest(RestClient.java:287)
	at Kapselung.post_document.main(post_document.java:59)

Or just checking the Elasticsearch version:

package Kapselung;

import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.rest_client.RestClientTransport;

public class getESClient_info_version_number {

	public static void main(String[] args) {
		String username = "elastic";
		String password = "JotkB5QY5v9IN0qRtvf6d5dL";
		String host = "gattinger-fourth.kb.us-central1.gcp.cloud.es.io";
		int port = 9243;
		RestClient restClient;
		ElasticsearchClient ESClient;

		// https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/connecting.html
		// https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/_basic_authentication.html
		final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
		credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
		HttpClientConfigCallback httpClientConfigCallback = new HttpClientConfigCallback() {
			@Override
			public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
				httpClientBuilder.disableAuthCaching();
				return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
			}
		};

		// Create the low-level client
		RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(host, port, "https"));
		restClientBuilder.setHttpClientConfigCallback(httpClientConfigCallback);
		restClient = restClientBuilder.build();

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

		// "productive code"
		try {
			System.out.println(ESClient.info().version().number());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}

Failure:

co.elastic.clients.transport.TransportException: [es/info] Missing [X-Elastic-Product] header. Please check that you are connecting to an Elasticsearch instance, and that any networking filters are preserving that header.
	at co.elastic.clients.transport.rest_client.RestClientTransport.checkProductHeader(RestClientTransport.java:351)
	at co.elastic.clients.transport.rest_client.RestClientTransport.getHighLevelResponse(RestClientTransport.java:253)
	at co.elastic.clients.transport.rest_client.RestClientTransport.performRequest(RestClientTransport.java:147)
	at co.elastic.clients.elasticsearch.ElasticsearchClient.info(ElasticsearchClient.java:976)
	at Kapselung.getESClient_info_version_number.main(getESClient_info_version_number.java:51)
Caused by: org.elasticsearch.client.ResponseException: method [GET], host [https://gattinger-fourth.kb.us-central1.gcp.cloud.es.io:9243], URI [/], status line [HTTP/1.1 200 OK]

And this is my pom.xml:


4.0.0 00003 00004 0.0.1-SNAPSHOT
<dependency>
  <groupId>co.elastic.clients</groupId>
  <artifactId>elasticsearch-java</artifactId>
  <version>8.2.0</version>
</dependency>
<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-databind</artifactId>
  <version>2.12.3</version>
</dependency>

<!-- benötigt falls ClassNotFoundException: jakarta.json.spi.JsonProvider
https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/installation.html -->
<dependency>
  <groupId>jakarta.json</groupId>
  <artifactId>jakarta.json-api</artifactId>
  <version>2.0.1</version>
</dependency>
<!-- -->
``` ``` Changing dependency from 8.2.0 to 8.4.0 didn't help.

So i don't know what actually to do. Do you?

Yes i know that i spread the password, it is intentional so somebody could help me by actually executing it. It is only a 2 weeks trial so i don't care about the logindata.

Thanks - Enomine

Hi @Michael_Gattinger Welcome to the community and thanks for trying Elastic Cloud

Your should try curl outside your java program...

You have a simple error you are pointing at kibana not elasticsearch...

gattinger-fourth.kb.us-central1.gcp.cloud.es.io
-----------------^^.. es not kb.....

correct

gattinger-fourth.es.us-central1.gcp.cloud.es.io
-----------------^^.. es not kb.....

$ curl -u elastic:JotkB5QY5v9IN0qRtvf6d5dL https://gattinger-fourth.es.us-central1.gcp.cloud.es.io
{
  "name" : "instance-0000000001",
  "cluster_name" : "b63255165d3f4cbb8263aa78cbfe9bff",
  "cluster_uuid" : "8UdrUU9zQvOkSbkfvhbhJg",
  "version" : {
    "number" : "8.4.3",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "42f05b9372a9a4a470db3b52817899b99a76ee73",
    "build_date" : "2022-10-04T07:17:24.662462378Z",
    "build_snapshot" : false,
    "lucene_version" : "9.3.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}

Now change your password immediately :slight_smile:

Hey thanks for your help. I see it was a layer 8 problem.

And here is the next layer 8 problem: I have no clue how to get there where you point me to.

As you have "Elastic Team" by your name i think you work for them. Then i propose that you tell them that it is hard to navigate from the point where i am stuck to the point where you want me to change the passwort. In summer there was something like "prices" or similar in the icon top right and when i clicked on that i landed somewhere where i could manage my stack. But this link does not exist any more. Now i have no clue how to get there. And one more: "prices" is not very intuitive to click on to get to stack management.

Thanks - Enomine

Log into the elastic cloud console

cloud.elastic.co

That is the management console where you can see your deployments.

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