2

I am sending requests to Elasticsearch over HTTP from a Java client using Jest. Since my requests must traverse the public Internet, I am using an Nginx proxy in front of Elasticsearch to provide SSL and HTTP Basic Auth. However, I don't see a way to set HTTP Basic Auth credentials with Jest.

Is it possible to use HTTP Basic Auth with Jest? If so how?

Ian Campbell
  • 23,484
  • 14
  • 36
  • 57
ljcundiff
  • 1,159
  • 1
  • 9
  • 14

1 Answers1

3

HTTP basic auth can be sent as a header.

String authHeader = "Basic " + new String(Base64.encodeBase64(String.format("%s:%s", username, password).getBytes()));

Index index = new Index.Builder(json)
          .index(indexName)
          .type(type)
          .id(id)
          .setHeader("Authorization", authHeader)
          .build();

JestResult result = client.execute(index);
ljcundiff
  • 1,159
  • 1
  • 9
  • 14