在Java客户端中使用用户名和密码(无SSL)连接到Elasticsearch,可以通过以下步骤实现:
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>7.15.1</version>
</dependency>
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
RestClientBuilder builder = RestClient.builder(
new HttpHost("localhost", 9200, "http")
);
RestClient restClient = builder.build();
String username = "your_username";
String password = "your_password";
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(username, password));
restClientBuilder.setHttpClientConfigCallback(httpClientBuilder -> {
httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
return httpClientBuilder;
});
Response response = restClient.performRequest(
"GET",
"/your_index/_search"
);
以上是在Java客户端中使用用户名和密码连接到Elasticsearch的基本步骤。根据具体的应用场景和需求,可以进一步使用Elasticsearch的API进行索引、搜索、聚合等操作。
腾讯云提供了Elasticsearch的托管服务,称为Tencent Cloud Elasticsearch。您可以通过以下链接了解更多关于Tencent Cloud Elasticsearch的信息和产品介绍:
请注意,本答案没有提及亚马逊AWS、Azure、阿里云、华为云、天翼云、GoDaddy、Namecheap、Google等流行的云计算品牌商,以符合问题要求。
领取专属 10元无门槛券
手把手带您无忧上云