• <bdo id='orKTY'></bdo><ul id='orKTY'></ul>
    <tfoot id='orKTY'></tfoot>

    <small id='orKTY'></small><noframes id='orKTY'>

    <i id='orKTY'><tr id='orKTY'><dt id='orKTY'><q id='orKTY'><span id='orKTY'><b id='orKTY'><form id='orKTY'><ins id='orKTY'></ins><ul id='orKTY'></ul><sub id='orKTY'></sub></form><legend id='orKTY'></legend><bdo id='orKTY'><pre id='orKTY'><center id='orKTY'></center></pre></bdo></b><th id='orKTY'></th></span></q></dt></tr></i><div id='orKTY'><tfoot id='orKTY'></tfoot><dl id='orKTY'><fieldset id='orKTY'></fieldset></dl></div>

      1. <legend id='orKTY'><style id='orKTY'><dir id='orKTY'><q id='orKTY'></q></dir></style></legend>

        Spring 中的 Elasticsearch HTTP 身份验证

        时间:2024-08-23

        1. <tfoot id='KuoVp'></tfoot>

            1. <small id='KuoVp'></small><noframes id='KuoVp'>

                <tbody id='KuoVp'></tbody>
                <bdo id='KuoVp'></bdo><ul id='KuoVp'></ul>
                <legend id='KuoVp'><style id='KuoVp'><dir id='KuoVp'><q id='KuoVp'></q></dir></style></legend>

                <i id='KuoVp'><tr id='KuoVp'><dt id='KuoVp'><q id='KuoVp'><span id='KuoVp'><b id='KuoVp'><form id='KuoVp'><ins id='KuoVp'></ins><ul id='KuoVp'></ul><sub id='KuoVp'></sub></form><legend id='KuoVp'></legend><bdo id='KuoVp'><pre id='KuoVp'><center id='KuoVp'></center></pre></bdo></b><th id='KuoVp'></th></span></q></dt></tr></i><div id='KuoVp'><tfoot id='KuoVp'></tfoot><dl id='KuoVp'><fieldset id='KuoVp'></fieldset></dl></div>
                  本文介绍了Spring 中的 Elasticsearch HTTP 身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想访问一个受用户名和密码保护的远程弹性搜索.https://[用户名]:[密码]]@aws-eu-west-1-portal1.dblayer.com:11109/

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

                  在 Spring 中使用 XML 配置我能够访问我的本地主机弹性,如下所示

                  In Spring using the XML config I was able to access my localhost elastic 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>
                  

                  到目前为止,我发现的唯一有用的文档是 PHP:https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_security.html

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

                  如何使用 XML 配置的 Spring 数据中的凭据连接到远程 elasticsearh?

                  How can I connect to a remote elasticsearh with credentials in Spring data with the XML config?

                  在 Mongo 中,我可以通过以下方法做到这一点

                  In Mongo I was able to do it by 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"/>
                  

                  推荐答案

                  Spring Data Elasticsearch 基于官方的 Elasticsearch Java Client,它使用二进制传输协议(而不是像 PHP 那样的 REST HTTP 协议).

                  Spring Data Elasticsearch is base on the official Elasticsearch Java Client which uses the binary Transport procol (not the REST HTTP procol like PHP).

                  如果您使用 Shield 来保护您的 Elasticsearch,那么您可以在传输客户端/传输协议上设置用户/密码

                  If you're using Shield to secure your Elasticsearch, then you can set the user/password on the Transport client/Transport procol

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

                  如果你不想在 Java 代码中使用 HTTP 协议,那么社区客户端:

                  If you wan't to use the HTTP protocol from Java code then there are to community clients:

                  • Jest 支持 HTTP 身份验证
                  • Elasticsearch HTTP 这是相当新的
                  • Jest which supports HTTP authentication
                  • Elasticsearch HTTP which is pretty new

                  但是这些解决方案与 Spring Data 不兼容

                  But these solutions are not compatible with Spring Data

                  这篇关于Spring 中的 Elasticsearch HTTP 身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Spring Data JPA 和 QueryDSL 下一篇:@Document 注释中的 MongoDB 和 SpEL 表达式

                  相关文章

                  <small id='MGI3B'></small><noframes id='MGI3B'>

                  <i id='MGI3B'><tr id='MGI3B'><dt id='MGI3B'><q id='MGI3B'><span id='MGI3B'><b id='MGI3B'><form id='MGI3B'><ins id='MGI3B'></ins><ul id='MGI3B'></ul><sub id='MGI3B'></sub></form><legend id='MGI3B'></legend><bdo id='MGI3B'><pre id='MGI3B'><center id='MGI3B'></center></pre></bdo></b><th id='MGI3B'></th></span></q></dt></tr></i><div id='MGI3B'><tfoot id='MGI3B'></tfoot><dl id='MGI3B'><fieldset id='MGI3B'></fieldset></dl></div>
                • <legend id='MGI3B'><style id='MGI3B'><dir id='MGI3B'><q id='MGI3B'></q></dir></style></legend>
                  <tfoot id='MGI3B'></tfoot>

                    <bdo id='MGI3B'></bdo><ul id='MGI3B'></ul>