消息:等待[30000] ms后的侦听器超时

时间:2018-05-29 18:12:10

标签: java

我正在尝试使用groovy和grails在Elasticsearch上实现简单的CRUD操作 有一段时间我能够创建一个索引,有些时候我得到了下面提到的超时异常,我已经尝试了很多方法,但没有一个是有效的。我卡在这里可以帮助我摆脱这个。 *低于例外情况我附上了我在这里使用的代码,请仔细阅读并检查是否正确

异常

  

错误| 2018-05-29 23:13:18,320 [http-bio-8080-exec-10]错误   errors.GrailsExceptionResolver - 处理时发生IOException   要求:[GET] / Sharama1 / person / addPerson           等待fo后监听器超时           项目清单          r [30000] ms。 Stacktrace如下:           消息:等待[30000] ms后的侦听器超时               线|方法            - >> 661 |进入org.elasticsearch.client.RestClient $ SyncResponseListener            - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -           | 220 | org.elasticsearch.client.RestClient中的performRequest           | 192 | performRequest。 。 。 。 。 。 。 。 。 。 。在''           | 428 |在org.elasticsearch.client.RestHighLevelClient中执行performRequest           | 414 | performRequestAndParseEntity。 。 。 。在''           | 299 |索引在''           | -2 | invoke0。 。 。 。 。 。 。 。 。 。 。 。 。 。 。在sun.reflect.NativeMethodAccessorImpl中           | 62 |调用''           | 43 |调用。 。 。 。 。 。 。 。 。 。 。 。 。 。 。在sun.reflect.DelegatingMethodAccessorImpl中           | 497 |在java.lang.reflect.Method中调用           | 1426 | jlrMethodInvoke。 。 。 。 。 。 。 。 。 。 。在org.springsource.loaded.ri.ReflectiveInterceptor中           | 189 |在org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite $ PojoCachedMethodSite中调用

*创建索引代码*

def addPerson={
    RestHighLevelClient client=ESService.getClient()
    Map<String,Object> jsonMap = new HashMap<>();
    jsonMap.put("firstName","abcd");
    jsonMap.put("lastName","xyz");
    jsonMap.put("date",new Date());
    jsonMap.put("message","Hugh data Index mapping");
    IndexRequest indexRequest = new IndexRequest("person1","hughdata","4").source(jsonMap);
    IndexResponse res =  client.index(indexRequest);
    String index = res.getIndex()
    String type = res.getType()
    String id = res.id
    long version = res.getVersion()
    DocWriteResponse.Result result = res.getResult();

    if (result == DocWriteResponse.Result.CREATED){
        println("index created = "+result)
    }
    else if (result == DocWriteResponse.Result.UPDATED){
        println("index Updated = "+result)
    }
    ["index":index,"type": type,"id":id,"version":version]
}

创建客户端代码

    class ESService {
    RestHighLevelClient client=null
    //TransportClient client=null
        def RestHighLevelClient getClient(){
            try {
                String hostname = "localhost"
                int port = 9200
                String scheme = "http"

                client = new RestHighLevelClient(RestClient.builder(new HttpHost("localhost",9200,"http")))

                boolean pingResponse = client.ping()

                if (pingResponse == true) {
                    print("connection established..." + pingResponse);
                } else {
                    print("connection not established. Try again : " + pingResponse)
                }
                /*return client*/
            }
            catch (ElasticsearchException e){
                e.printStackTrace()
            }
            return client
        }
}

Buildconfig.groovy

 dependencies {
    // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
    // runtime 'mysql:mysql-connector-java:5.1.27'
    // runtime 'org.postgresql:postgresql:9.3-1100-jdbc41'
    test "org.grails:grails-datastore-test-support:1.0-grails-2.3"
    compile group: 'org.elasticsearch', name: 'elasticsearch', version: '6.0.1'
    compile group: 'org.elasticsearch.client', name: 'elasticsearch-rest-high-level-client', version: '6.0.1'
    compile('com.amazonaws:aws-java-sdk-elasticsearch:1.11.123')
    compile('com.amazonaws:aws-java-sdk-elasticloadbalancingv2:1.11.123')
}

0 个答案:

没有答案