在我的 Scala 项目中,我试图用新的 RestHighLevelClient 更改旧的 transportClient 以连接到 Elasticsearch (6.1)。
但是我在尝试创建 BulkProcessor 时遇到问题,我不知道如何将此示例从 Java 转换为 Scala
`BulkProcessor.Builder builder = BulkProcessor.builder(client::bulkAsync, listener);`
我的代码是这样的:
val client=new RestHighLevelClient(
RestClient.builder(
new HttpHost("localhost", 9200, "http") ) )
val builder: BulkProcessor.Builder =BulkProcessor.builder(client, listener)
但我收到此错误:
overloaded method value builder with alternatives:
[error] (x$1: java.util.function.BiConsumer[org.elasticsearch.action.bulk.BulkRequest,org.elasticsearch.action.ActionListener[org.elasticsearch.action.bulk.BulkResponse]],x$2: org.elasticsearch.action.bulk.BulkProcessor.Listener)org.elasticsearch.action.bulk.BulkProcessor.Builder <and>
[error] (x$1: org.elasticsearch.client.Client,x$2: org.elasticsearch.action.bulk.BulkProcessor.Listener)org.elasticsearch.action.bulk.BulkProcessor.Builder
[error] cannot be applied to (org.elasticsearch.client.RestHighLevelClient, org.elasticsearch.action.bulk.BulkProcessor.Listener)
[error] val builder: BulkProcessor.Builder =BulkProcessor.builder(client, listener)
如果我尝试将“ client::bulkAsync
”转换为“ client.bulkAsync _
”或“ client::bulkAsync(_._._)
”,则会出现其他错误:
type mismatch;
[error] found : org.apache.http.Header*
[error] required: org.apache.http.Header
[error] var bulkProcessor =BulkProcessor.builder(client.bulkAsync(_,_,_),listener)
这是 Java 中的 bulkAsync 方法:
public final void bulkAsync(BulkRequest bulkRequest, ActionListener<BulkResponse> listener, Header... headers) {
有人在 Scala 中使用过 RestHighLevelClient 和 BulkProcessor 吗?或者知道如何解决这个错误?