Elasticsearch HTTP Authentication in Spring

I want to access a remote elasticsearch that is protected by a username and password. https: // [username]: [password] @ aws-eu-west-1-portal1.dblayer.com: 11109 /

In Spring, using an XML configuration, I was able to access my local elastic move, as shown below

<!-- ElasticSearch -->
<elasticsearch:repositories base-package="be.smartsearch.service.repository.elasticsearch" />

<elasticsearch:transport-client id="esClient" cluster-nodes="localhost:9300" />

<bean id="elasticsearchTemplate" class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
  <constructor-arg name="client" ref="esClient" />
</bean>

The only useful documentation I've found so far for PHP is: https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_security.html

How can I connect to remote elasticsearh with credentials in Spring data with XML configuration?

UPDATE 1

In Mongo, I was able to do this using the following method

<!-- Mongo -->
<mongo:mongo host="${mongo.host}" port="${mongo.port}"/>

<mongo:db-factory dbname="SmartSearchAfterDemo" mongo-ref="mongo" username="${mongo.user}" password="${mongo.password}"/>
<!--<mongo:db-factory dbname="${mongo.dbname}" mongo-ref="mongo"/> -->

<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
    <constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/>
</bean>

<mongo:repositories base-package="be.smartsearch.service.repository.mongo"/>
+4
2

Spring Data Elasticsearch Elasticearch Java Client, ( HTTP- REST, PHP).

Shield Elasticsearch, / /

TransportClient client = TransportClient.builder()
    .addPlugin(ShieldPlugin.class)
    .settings(Settings.builder()
        .put("cluster.name", "yourcluster")
        .put("shield.user", "youruser:yourpassword")
        ...
        .build())

HTTP- Java, :

Spring Data​​p >

+2

ElasticSearch Docker, X-Pack:

5.5, , Spring Data ElasticSearch . , , :

  1. org.elasticsearch.client:x-pack-transport. , build.gradle/pom.xml: https://artifacts.elastic.co/maven :

    {maven {url " https://artifacts.elastic.co/maven "}}

  2. X-Pack:

    import org.elasticsearch.xpack.client.PreBuiltXPackTransportClient;
    ...
    TransportClient client = new PreBuiltXPackTransportClient(Settings.builder()
        .put("cluster.name", "myClusterName")
        .put("xpack.security.user", "transport_client_user:changeme")
        ...
        .build())
    .addTransportAddress(new InetSocketTransportAddress("localhost", 9300))
    .addTransportAddress(new InetSocketTransportAddress("localhost", 9301));
    

: HTTP, HTTPS-, , .

+1

Source: https://habr.com/ru/post/1615218/


All Articles