ElasticSearch Java API异步写入
我对ElasticSearch比较陌生,我注意到当您启动ElasticSearchJava客户端时,它会启动大量线程(~50个) 我试图利用这一点,但buy找不到对ES进行异步写入(索引)的方法 官方API建议使用:ElasticSearch Java API异步写入,java,multithreading,asynchronous,elasticsearch,Java,Multithreading,Asynchronous,elasticsearch,我对ElasticSearch比较陌生,我注意到当您启动ElasticSearchJava客户端时,它会启动大量线程(~50个) 我试图利用这一点,但buy找不到对ES进行异步写入(索引)的方法 官方API建议使用: IndexResponse response = client.prepareIndex(indexName, documentName) .setSource(mapper.writeValueAsString(data)) .ge
IndexResponse response = client.prepareIndex(indexName, documentName)
.setSource(mapper.writeValueAsString(data))
.get();
即使我在一个新的线程上运行它,它仍然在等待响应时阻塞,其中包含新创建的ID等等
是否可以以异步方式写入ES,而不必再创建50个本地线程来匹配ES的50个内部线程?如果有人无意中发现了这一点,解决方案是使用
.execute()
,它返回一个ListenableActionFuture
e、 g
client.prepareIndex(indexName, documentName)
.setSource(mapper.writeValueAsString(data))
.execute();