我的springboot Elastic Integration Code编写模型时面临的问题

时间:2019-04-26 09:37:22

标签: spring-boot elasticsearch spring-data-jpa

我想通过查询从springboot api端点的弹性索引中获取数据。

弹性版本6.X。

我需要一些人来帮助编写模型,存储库,服务和服务实现。我是新的弹性和弹簧靴。 请帮助我。

我能够从springboot成功连接松紧带。 现在,我想通过查询获取弹性索引数据。

ElasticConfiguration.java

package com.websystique.springboot.configuration;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;

import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ElasticConfiguration {

    @Value("${datasource.sampleapp.elasticsearch_host:localhost}")
    public String host;
    @Value("${datasource.sampleapp.elasticsearch_port:9300}")
    public int port;

    public String getHost() {
        return host;
    }

    public int getPort() {
        return port;
    }

     @Bean
     public Client client() {
     TransportClient client = null;
         try {
     System.out.println("host:" + host + "port:" + port);
     Settings settings = Settings.builder().put("cluster.name", "elasticsearch").put("client.transport.sniff", false).build();
     client = new PreBuiltTransportClient(settings).addTransportAddress(new TransportAddress(InetAddress.getByName(getHost()), 9300));
     } catch (UnknownHostException e) {
     e.printStackTrace();
     }
     return client;
     }


}

弹性索引json: 卷曲http://localhost:200/test/_search

{
"took":2,
"timed_out":false,
"_shards":{
"total":5,
"successful":5,
"skipped":0,
"failed":0
},
"hits":{
"total":621,
"max_score":1.0,
"hits":[
{
"_index":"test",
"_type":"random",
"_id":"{17da802b-ddbd-439f-86fd-92447c2b91eb}",
"_score":1.0,
"_source":{
"Data":{
"id":"{17da802b-ddbd-439f-86fd-92447c2b91eb}",
"parameters":[
{
"key":"dataflowId",
"value":"5e88476a-d241-4ef7-9654-16f2b35c6cce"
},
{
"key":"dataflowName",
"value":"Policy_Pt_DF"
},
{
"key":"destination",
"value":"repo2@00-00A5C8-4E8CE1-40F393-B18919[1-1-F]"
},
{
"key":"moverType",
"value":"eMOVER_BATCH"
},
{
"key":"operationId",
"value":"1"
},
{
"key":"policyId",
"value":"fbd5d40a4eac4c6e8b23800e5a4bd97b"
},
{
"key":"policyName",
"value":"Plocity_pl"
},
{
"key":"policyVersion",
"value":"1"
},
{
"key":"sessionId",
"value":"hdid-repo90@BC-AAGBPL-AENMIQ-VBHPK9-T8UQCH[0-1-3]#1555195303002-2676-186"
},
{
"key":"source",
"value":"hdid-client90@BW-RSQUZZ-TT44ZB-HKUTJI-EVP299[0-1-2]"
}
],
"timeStarted":"2019-04-13T22:52:18Z",
"timeUpdated":"2019-04-13T22:52:35Z",
"description":"Initial Resynchronization of FileSystem Data to Repository Store",
"actions":[
],
"timeCompleted":"2019-04-13T22:52:35Z",
"progress":"Stage 13 of 13",
"type":"eJOBTYPE_BACKUP",
"status":"eJOB_CANCELLED",
"subType":{
"id":"Resynchronize Repository Store",
"subSystem":"Repository"
},
"mainNode":{
"id":"hdid-client90@BW-RSQUZZ-TT44ZB-HKUTJI-EVP299[0-1-2]",
"instance":61
}
},
"date":"2019-04-13T22:52:18Z",
"MainNode":"hdid-client90"
}
}]
}
}

0 个答案:

没有答案