【问题标题】:ElasticSearch Java API asynchronous writingElasticSearch Java API 异步编写
【发布时间】:2016-11-15 11:26:12
【问题描述】:

我对 ElasticSearch 比较陌生,我注意到当您启动 elasticsearch Java 客户端时,它会启动大量线程 (~50)。

我试图利用这一点,buy 找不到向 ES 进行异步写入(索引)的方法。

官方API建议是使用:

IndexResponse response = client.prepareIndex(indexName, documentName)
            .setSource(mapper.writeValueAsString(data))
            .get();

即使我在新线程上运行它,它在等待响应时仍然处于阻塞状态,其中包含新创建的 ID 等。

是否可以以异步方式写入 ES,而不必创建另外 50 个本地线程来匹配 ES 的 50 个内部线程?

【问题讨论】:

    标签: java multithreading asynchronous elasticsearch


    【解决方案1】:

    如果有人偶然发现这一点,解决方案是使用.execute(),它返回一个ListenableActionFuture<Response>。

    例如

    client.prepareIndex(indexName, documentName)
            .setSource(mapper.writeValueAsString(data))
            .execute();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-12
      • 2020-07-19
      • 1970-01-01
      • 2013-08-13
      • 1970-01-01
      相关资源
      最近更新 更多