Как сделать Elasticsearch embedded доступным через localhost: 9200

Я играю с весна-ботинок-образец-данные-elastcisearch. Я изменил pom и добавил:

SampleElasticsearchApplicationWebXml extends SpringBootServletInitializer 

для запуска со встроенным Tomcat. Мое приложение.свойства

spring.data.elasticsearch.http-enabled=true
spring.data.elasticsearch.local=true

Я хочу иметь возможность подключиться к localhost: 9200 для использования elasticsearch-head или другого клиента JS. Что я упускаю? Спасибо, Милан!--5-->

2 ответов


вы должны определить это для себя, потому что NodeClientFactoryBean вариант http.enabled но ElasticSearchAutoConfiguration ( пока) не устанавливает его.

@Configuration
@EnableConfigurationProperties(ElasticsearchProperties.class)
public class ElasticsearchConfiguration implements DisposableBean {

    private static Log logger = LogFactory.getLog(ElasticsearchConfiguration.class);

    @Autowired
    private ElasticsearchProperties properties;

    private NodeClient client;

    @Bean
    public ElasticsearchTemplate elasticsearchTemplate() {
        return new ElasticsearchTemplate(esClient());
    }

    @Bean
    public Client esClient() {
        try {
            if (logger.isInfoEnabled()) {
                logger.info("Starting Elasticsearch client");
            }
            NodeBuilder nodeBuilder = new NodeBuilder();
            nodeBuilder
                    .clusterName(this.properties.getClusterName())
                    .local(false)
            ;
            nodeBuilder.settings()
                    .put("http.enabled", true)
            ;
            this.client = (NodeClient)nodeBuilder.node().client();
            return this.client;
        }
        catch (Exception ex) {
            throw new IllegalStateException(ex);
        }
    }

    @Override
    public void destroy() throws Exception {
        if (this.client != null) {
            try {
                if (logger.isInfoEnabled()) {
                    logger.info("Closing Elasticsearch client");
                }
                if (this.client != null) {
                    this.client.close();
                }
            }
            catch (final Exception ex) {
                if (logger.isErrorEnabled()) {
                    logger.error("Error closing Elasticsearch client: ", ex);
                }
            }
        }
    }
}

по данным этот билет, Теперь вы можете просто добавить эту строку в файлах конфигурации:

spring.data.elasticsearch.properties.http.enabled=true