简体   繁体   English

如何为 Azure 托管服务(无端口)指定 elasticsearch spring 引导配置

[英]How can I specify elasticsearch spring boot configuration for Azure managed Service (without port)

I created an Azure managed Service for ElasticSearch.我为 ElasticSearch 创建了一个 Azure 托管服务。 Now I want to access it with my Spring Boot Elastic Application.现在我想用我的 Spring Boot Elastic Application 访问它。

NOTE: I hide the real URL with the placeholder MyCustomAzureURLwithoutPort.com.注意:我用占位符 MyCustomAzureURLwithoutPort.com 隐藏了真正的 URL。 In reality it is something like https://myclustername.es.REGION.azure.elastic-cloud.com实际上,它类似于https://myclustername.es.REGION.azure.elastic-cloud.com

My ElasticConfig is:我的弹性配置是:

@Configuration
@EnableElasticsearchRepositories(basePackages = "org.elastic.repositories")
@ComponentScan(basePackages = { "org.elastic" })
public class ElasticsearchClientConfig extends AbstractElasticsearchConfiguration {

    @Override
    @Bean
    public RestHighLevelClient elasticsearchClient() {


        final ClientConfiguration clientConfiguration = 
                ClientConfiguration
                .builder()
                .connectedTo("https://MyCustomAzureURLwithoutPort.com")
                .withBasicAuth(user, pw)
                .build();

        return RestClients
                .create(clientConfiguration)
                .rest();
    }

But I keep getting an error like this:但我不断收到这样的错误:

11:41:59.972 [] [] [main]
                ERROR o.s.boot.SpringApplication - Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productsearchappApplication': Invocation of init method failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: https:MyCustomAzureURLwithoutPort.com; nested exception is java.lang.RuntimeException: https:MyCustomAzureURLwithoutPort.com
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:160)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:415)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1786)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
    at io.pratik.elasticsearch.productsearchapp.ProductsearchappApplication.main(ProductsearchappApplication.java:38)
Caused by: org.springframework.dao.DataAccessResourceFailureException: https:MyCustomAzureURLwithoutPort.com; nested exception is java.lang.RuntimeException: https:MyCustomAzureURLwithoutPort.com
    at org.springframework.data.elasticsearch.core.ElasticsearchExceptionTranslator.translateExceptionIfPossible(ElasticsearchExceptionTranslator.java:76)
    at org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.translateException(ElasticsearchRestTemplate.java:378)
    at org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.execute(ElasticsearchRestTemplate.java:361)
    at org.springframework.data.elasticsearch.core.DefaultIndexOperations.doRefresh(DefaultIndexOperations.java:175)
    at org.springframework.data.elasticsearch.core.AbstractDefaultIndexOperations.refresh(AbstractDefaultIndexOperations.java:159)
    at io.pratik.elasticsearch.productsearchapp.ProductsearchappApplication.buildIndex(ProductsearchappApplication.java:50)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.base/java.lang.reflect.Method.invoke(Method.java:577)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:389)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:333)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:157)
    ... 19 common frames omitted
Caused by: java.lang.RuntimeException: https:MyCustomAzureURLwithoutPort.com
    at org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.translateException(ElasticsearchRestTemplate.java:376)
    ... 28 common frames omitted
Caused by: java.io.IOException: https:MyCustomAzureURLwithoutPort.com
    at org.elasticsearch.client.RestClient.extractAndWrapCause(RestClient.java:828)
    at org.elasticsearch.client.RestClient.performRequest(RestClient.java:248)
    at org.elasticsearch.client.RestClient.performRequest(RestClient.java:235)
    at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1514)
    at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1484)
    at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1454)
    at org.elasticsearch.client.IndicesClient.refresh(IndicesClient.java:553)
    at org.springframework.data.elasticsearch.core.DefaultIndexOperations.lambda$doRefresh$9(DefaultIndexOperations.java:175)
    at org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.execute(ElasticsearchRestTemplate.java:359)
    ... 27 common frames omitted
Caused by: java.net.UnknownHostException: https:MyCustomAzureURLwithoutPort.com
    at java.base/java.net.InetAddress$CachedAddresses.get(InetAddress.java:948)
    at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1638)
    at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1504)
    at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:45)
    at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager$InternalAddressResolver.resolveRemoteAddress(PoolingNHttpClientConnectionManager.java:664)
    at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager$InternalAddressResolver.resolveRemoteAddress(PoolingNHttpClientConnectionManager.java:635)
    at org.apache.http.nio.pool.AbstractNIOConnPool.processPendingRequest(AbstractNIOConnPool.java:474)
    at org.apache.http.nio.pool.AbstractNIOConnPool.lease(AbstractNIOConnPool.java:280)
    at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.requestConnection(PoolingNHttpClientConnectionManager.java:295)
    at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.requestConnection(AbstractClientExchangeHandler.java:377)
    at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.start(DefaultClientExchangeHandlerImpl.java:129)
    at org.apache.http.impl.nio.client.InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:141)
    at org.elasticsearch.client.RestClient.performRequest(RestClient.java:244)
    ... 34 common frames omitted
Disconnected from the target VM, address: '127.0.0.1:52567', transport: 'socket'

I also tried the URL with Port 443 ( https://myclustername.es.REGION.azure.elastic-cloud.com:443 ), that's what the Stacktrace is copied from, but this didn't worked either. I also tried the URL with Port 443 ( https://myclustername.es.REGION.azure.elastic-cloud.com:443 ), that's what the Stacktrace is copied from, but this didn't worked either.

Anyone have an Idea?有人有想法吗? Need the BasicAuth and connect to this URL without Port.需要 BasicAuth 并在没有端口的情况下连接到此 URL。

Thanks!谢谢!

Elastic cloud uses 9243 and 443 .弹性云使用9243443 Therefore, try with 9243 .因此,请尝试使用9243

You can find the reason here: Why does Elastic Cloud provides a specialized port (9243) instead of only using the default one (443)?您可以在这里找到原因: 为什么 Elastic Cloud 提供专用端口(9243)而不是仅使用默认端口(443)?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM