简体   繁体   English

弹性搜索:将客户端传输到高级其余客户端

[英]Elastic Search: Transport Client to High Level Rest Client

I am trying to establish a connection to my local Elastic Search Instance. 我正在尝试建立到本地弹性搜索实例的连接。

Previously, I used transport client to create 以前,我使用传输客户端来创建

  1. Controller. 控制器。
  2. Config 设定档
  3. Loader(using @PostConstruct) 加载器(使用@PostConstruct)
  4. Repository(Extends ElasticSearchRepositores) 存储库(扩展ElasticSearchRepositores)
  5. Entity(@Document annotation) 实体(@Document批注)

I tried to achieve the same functionality using HighLevel Rest Client. 我尝试使用HighLevel Rest Client实现相同的功能。

Following are my components: 以下是我的组件:

@Configuration
@EnableElasticsearchRepositories(basePackages = "com.abd.def.hig.monitor.repo")
public class ElasticsearchConfig {

    @Bean(destroyMethod = "close")
    public RestHighLevelClient client() {
        RestHighLevelClient client = new RestHighLevelClient(
        RestClient.builder(new HttpHost("localhost",9200,"http")));
         // System.out.println("client is" + client.indices().get());
        return client;

      }
}
public interface ElasticSearchRepo extends ElasticsearchRepository<Store,Long> {

}
package com.fg.pos.tpdjavaagent.monitor.model;

import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import com.fg.pos.tpdjavaagent.monitor.model.ApplicationStats;

@Document(indexName = "storedtls", type = "storedtls")
public class Store {

    @Id
    String siteCode;

    String siteName;

    String formatCode;

    String zone;

    String posType;

    String ipAddress;

    String tpAdmin;

    String applicationVersion;

    String osType;

    String ISPType;

    public Store(String siteCode, String siteName, String formatCode, String zone, String posType, String ipAddress,
            String tpAdmin, String applicationVersion, String osType, String iSPType,
            ApplicationStats applicationStats) {
        super();
        this.siteCode = siteCode;
        this.siteName = siteName;
        this.formatCode = formatCode;
        this.zone = zone;
        this.posType = posType;
        this.ipAddress = ipAddress;
        this.tpAdmin = tpAdmin;
        this.applicationVersion = applicationVersion;
        this.osType = osType;
        ISPType = iSPType;
        this.applicationStats = applicationStats;
    }

    ApplicationStats applicationStats;

    public String getSiteCode() {
        return siteCode;
    }

    public void setSiteCode(String siteCode) {
        this.siteCode = siteCode;
    }

    public String getSiteName() {
        return siteName;
    }

    public void setSiteName(String siteName) {
        this.siteName = siteName;
    }

    public String getFormatCode() {
        return formatCode;
    }

    public void setFormatCode(String formatCode) {
        this.formatCode = formatCode;
    }

    public String getZone() {
        return zone;
    }

    public void setZone(String zone) {
        this.zone = zone;
    }

    public String getPosType() {
        return posType;
    }

    public void setPosType(String posType) {
        this.posType = posType;
    }

    public String getIpAddress() {
        return ipAddress;
    }

    public void setIpAddress(String ipAddress) {
        this.ipAddress = ipAddress;
    }

    public String getTpAdmin() {
        return tpAdmin;
    }

    public void setTpAdmin(String tpAdmin) {
        this.tpAdmin = tpAdmin;
    }

    public String getApplicationVersion() {
        return applicationVersion;
    }

    public void setApplicationVersion(String applicationVersion) {
        this.applicationVersion = applicationVersion;
    }

    public String getOsType() {
        return osType;
    }

    public void setOsType(String osType) {
        this.osType = osType;
    }

    public String getISPType() {
        return ISPType;
    }

    public void setISPType(String iSPType) {
        ISPType = iSPType;
    }

    public ApplicationStats getApplicationStats() {
        return applicationStats;
    }

    public void setApplicationStats(ApplicationStats applicationStats) {
        this.applicationStats = applicationStats;
    }


}

When I remove @EnableElasticsearchRepositories from the config file, everything works fine. 当我从配置文件中删除@EnableElasticsearchRepositories时,一切正常。 However, when I add the same, I get the error stated below: 但是,当我添加相同的内容时,出现以下错误:

Consider defining a bean named 'elasticsearchTemplate' in your configuration.

One way around to resolve this issue when I used transport client was to simply add: 当我使用传输客户端时解决此问题的一种方法是简单地添加:

@Bean
    ElasticsearchOperations elasticsearchTemplate() throws Exception {
        return new ElasticsearchTemplate(client());
    }

Inside my configurations. 在我的配置中。 However, the client method shows error when High Level Client is used because it is of Client type. 但是,使用高级客户端时,客户端方法会显示错误,因为它属于客户端类型。

Please let me know if anything is possible to fix this. 请让我知道是否有可能解决此问题。

Thanks in advance. 提前致谢。

New Spring Data ElasticSearch Upgraded their method. 新的Spring Data ElasticSearch升级了他们的方法。 So instead of: 所以代替:

@Bean
    ElasticsearchOperations elasticsearchTemplate() throws Exception {
        return new ElasticsearchTemplate(client());
    }

It is supposed to be: 应该是:

@Bean
    ElasticsearchOperations elasticsearchTemplate() throws Exception {
        return new ElasticsearchRestTemplate(client());
    }

暂无
暂无

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

相关问题 Spring 数据弹性搜索与 Java 高级 REST 客户端 - Spring Data Elastic Search vs Java High Level REST Client 弹性搜索 rest 高级客户端出现以下错误 - Getting below error in elastic search rest high level client 为什么在弹性搜索中引入 Java 高级 REST 客户端? - Why Java High Level REST Client got introduced in Elastic search? 如何通过 Java 高级 rest 客户端在 Elastic Search 中使用多个字段进行搜索 - How to search using multiple fields in Elastic Search through Java high level rest client 如何使用 JAVA 高级 REST 客户端创建弹性搜索索引? - How can I create an elastic search index with the JAVA high level REST client? 如何在 Elastic High Level Rest 客户端中使用 search_after 进行分页 - How to use search_after in Elastic High Level Rest Client for pagination 为什么 filterQuery 在用于 JAVA 的 Elastic Search 的高级 REST 客户端中不起作用? - Why does filterQuery not work in Elastic Search's high level REST client for JAVA? 通过 rest 高级客户端在弹性搜索中创建类型内部索引 - Creating type inside index in elastic search through rest high level client 将映射与 Elastic Search 的高级 REST JAVA 客户端异步放置 - 不推荐使用的错误 - Put mapping with Elastic Search's High level REST JAVA client asynchronously - deprecated error 使用 Rest 高级客户端检索或插入数据到 Elastic Search 时出现 SocketTimeoutException - SocketTimeoutException while retrieving or inserting data into Elastic Search by using Rest High Level Client
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM