I was going through these docs to create an elastic search index from Elastic's high level JAVA REST client. It seems to skip over steps for authenticating with my elastic cloud account. Can someone please point me toward the relevant documentation?
I launched my elastic search instance and copied the endpoint URL into my client code.
I initially had connection errors and now there are none. Only authentication errors. So, I'm pretty sure I'm connecting with the correct endpoint URL and need to authenticate somehow - perhaps with a header.
Now, I am seeing this error:
Elasticsearch exception [type=security_exception, reason=action [indices:data/write/index] requires authentication]
I can view the endpoint of my Elastic Search deployment with no problems from Postman with this command: GET https://:@d97215aee2.us-east-1.aws.found.io:9243
I can also create an index using this command from Postman... PUT https://elastic:4YQIMXfoSZ9mXPgY1fj7T5BU@d97218f74f6d48489b355dd7d665aee2.us-east-1.aws.found.io:9243/. Yet, I cannot do the same from the Java code.
Here is the state of my Java code. It is pretty much the code from these tutorial pages.
import java.io.IOException;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.apache.http.HttpHost;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;
@Path("/elasticsearch")
public class ElasticSearchService {
@POST
public void createElasticIndex() throws IOException {
RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(
new HttpHost("d9<deleted a bunch of characters for privacy>7d665aee2.us-east-1.aws.found.io", 9243, "https")));
IndexRequest request = new IndexRequest(
"posts",
"doc",
"1");
String jsonString = "{" +
"\"user\":\"kimchy\"," +
"\"postDate\":\"2013-01-30\"," +
"\"message\":\"trying out Elasticsearch\"" +
"}";
request.source(jsonString, XContentType.JSON);
client.close();
}
}
I have also tried updating the URL address with our username and password as suggested by this post: ElasticSearch authentication error with ElasticCloud?
Essentially, I updated my URL like this...
RestClient.builder(
new HttpHost(
"<my user name>:<my password>@d97218<hidden characters>d665aee2.us-east-1.aws.found.io",
9243, "https")));
This did not work for me. I am guessing this person wasn't using the new Elastic High Level REST client. I received this error:
org.glassfish.jersey.server.internal.process.MappableException: java.io.IOException: :@d97265aee2.us-east-1.aws.found.io: invalid IPv6 address