Я попытался подключиться к удаленному небезопасному поисковому экземпляру elasti c с http URL (http://hostname: порт ) из RestHighLevelClient, используя приведенный ниже код, и это было успешно.
package com.*i;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;
import org.springframework.data.elasticsearch.core.ElasticsearchEntityMapper;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.EntityMapper;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
@Configuration
@EnableElasticsearchRepositories
public class ElasticRestClientConfig extends AbstractElasticsearchConfiguration {
@Value("${spring.elasticsearch.rest.uris}")
String elasticURL;
@Value("${spring.elasticsearch.rest.username}")
String username;
@Value("${spring.elasticsearch.rest.password}")
String password;
@Bean
public RestHighLevelClient elasticsearchClient() {
final ClientConfiguration clientConfiguration = ClientConfiguration.builder()
.connectedTo(elasticURL)
.withBasicAuth(username, password)
.withConnectTimeout(10000*60)
.build();
return RestClients.create(clientConfiguration).rest();
}
@Bean
ElasticsearchRestTemplate elasticsearchTemplate() {
return new ElasticsearchRestTemplate(elasticsearchClient());
}
@Bean
@Override
public EntityMapper entityMapper() {
ElasticsearchEntityMapper entityMapper = new ElasticsearchEntityMapper(elasticsearchMappingContext(),
new DefaultConversionService());
entityMapper.setConversions(elasticsearchCustomConversions());
return entityMapper;
}
}
Теперь я хочу подключиться к удаленному защищенному эластичному c поисковому экземпляру одного узла (https://hostname: порт ) с тем же кодом, что и выше, и он не работает. Я просмотрел доступные вопросы на разных платформах и не смог их реализовать, так как я новичок в этом. Ищите способ подключиться к защищенному экземпляру ES с помощью RestHighLevelClient, как описано выше.