# BulkProcessor creation using RestHighLevelClient compilation error on ES5.6

**URL:** <https://discuss.elastic.co/t/bulkprocessor-creation-using-resthighlevelclient-compilation-error-on-es5-6/140573>\
**Category:** Elasticsearch\
**Created:** [July 18, 2018, 2:07pm UTC](https://discuss.elastic.co/t/bulkprocessor-creation-using-resthighlevelclient-compilation-error-on-es5-6/140573 "2018-07-18T14:07:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rappahannock](https://avatars.discourse-cdn.com/v4/letter/r/dc4da7/32.png) [@Rappahannock](https://discuss.elastic.co/u/Rappahannock)\
**Post date:** [July 18, 2018, 2:07pm UTC](https://discuss.elastic.co/t/bulkprocessor-creation-using-resthighlevelclient-compilation-error-on-es5-6/140573/1 "2018-07-18T14:07:37Z")

</div>

I have an issue when compiling the following code on ES5.6.6:

```auto
BulkProcessor bulkProcessor = BulkProcessor.builder(restHighLevelClient::bulkAsync, listener).build();

```

The following compilation error occurs:

```auto
/test-bulkprocessor/src/main/java/com/rappahannock/elasticsearch/ESConfiguration.java: incompatible types: org.elasticsearch.client.Client is not a functional interface
    multiple non-overriding abstract methods found in interface org.elasticsearch.client.Client

```

The same code compiles without error on ES6.2.4.

But in my project I cannot switch to a higher client version, because server version cannot be easily updated.

Test repository for error reproduction:

> **[Rappahannock/test-bulkprocessor](https://github.com/Rappahannock/test-bulkprocessor)**
>
> Contribute to test-bulkprocessor development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![Rappahannock](https://avatars.discourse-cdn.com/v4/letter/r/dc4da7/32.png) [@Rappahannock](https://discuss.elastic.co/u/Rappahannock)\
**Post date:** [July 18, 2018, 2:12pm UTC](https://discuss.elastic.co/t/bulkprocessor-creation-using-resthighlevelclient-compilation-error-on-es5-6/140573/2 "2018-07-18T14:12:19Z")

</div>

Similar problem has been discussed in the following topics:

> [@Headache with RestHighLevelClient and bulkprocessor](https://discuss.elastic.co/t/headache-with-resthighlevelclient-and-bulkprocessor/106072):
>
> BulkProcessor.Builder builder = BulkProcessor.builder(client::bulkAsync, new BulkProcessorListener()); this line is complaining The target type of this expression must be a functional interface the error is this part: builder(client::bulkAsync, any idea? please help import org.elasticsearch.client.RestHighLevelClient; RestHighLevelClient client; environment: java 8, eclipse

> [@\[BUG\] You can use BulkProcessor with high-level client in 5.6 version](https://discuss.elastic.co/t/bug-you-can-use-bulkprocessor-with-high-level-client-in-5-6-version/123602):
>
> Hi team, Thanks in advance I try to create a BulkProcessor like [https://www.elastic.co/guide/en/elasticsearch/client/java-rest/5.6/java-rest-high-document-bulk.html](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/5.6/java-rest-high-document-bulk.html) with the high-level client in the version 5.6 but I get this compilation error at this point: ... RestHighLevelClient rHLClient ... BulkProcessor bulkProcessor = BulkProcessor.builder(rHLClient::bulkAsync, listener,threadPool).build(); "Client is not a functional interface" If there is a better way to use that, please advis…

But I don't find there how to solve my problem.

This comment suggests that it's a bug in Eclipse IDE: [[BUG] You can use BulkProcessor with high-level client in 5.6 version - #9 by juanaramis](https://discuss.elastic.co/t/bug-you-can-use-bulkprocessor-with-high-level-client-in-5-6-version/123602/9)

But I compile in another IDE, also I compile from command line using maven 3.0.4.

Here is an extract from my maven compilation log:

```auto
Apache Maven 3.0.4 (r1232337; 2012-01-17 12:44:56+0400)
Maven home: F:\1_Tools\apache-maven-3.0.4
Java version: 1.8.0_77, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_77\jre
Default locale: en_US, platform encoding: Cp1251
OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"
[INFO] Error stacktraces are turned on.
[DEBUG] Reading global settings from F:\1_Tools\apache-maven-3.0.4\conf\settings.xml
[DEBUG] Reading user settings from C:\...\.m2\settings.xml
[DEBUG] Using local repository at C:\m2
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10 for C:\m2
...
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /F:/GIT/0_Examples/test-bulkprocessor/src/main/java/com/rappahannock/elasticsearch/ESConfiguration.java: incompatible types: org.elasticsearch.client.Client is not a functional interface
    multiple non-overriding abstract methods found in interface org.elasticsearch.client.Client
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.067s
[INFO] Finished at: Wed Jul 18 17:28:21 GET 2018
[INFO] Final Memory: 26M/306M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project test-bulkprocessor: Compilation failure
[ERROR] /F:/GIT/0_Examples/test-bulkprocessor/src/main/java/com/rappahannock/elasticsearch/ESConfiguration.java: incompatible types: org.elasticsearch.client.Client is not a functional interface
[ERROR] multiple non-overriding abstract methods found in interface org.elasticsearch.client.Client
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project test-bulkprocessor: Compilation failure
/F:/GIT/0_Examples/test-bulkprocessor/src/main/java/com/rappahannock/elasticsearch/ESConfiguration.java: incompatible types: org.elasticsearch.client.Client is not a functional interface
    multiple non-overriding abstract methods found in interface org.elasticsearch.client.Client

	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
/F:/GIT/0_Examples/test-bulkprocessor/src/main/java/com/rappahannock/elasticsearch/ESConfiguration.java: incompatible types: org.elasticsearch.client.Client is not a functional interface
    multiple non-overriding abstract methods found in interface org.elasticsearch.client.Client

	at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:858)
	at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
	... 19 more

```

---

<div class="post-metadata">

**Author:** ![juanaramis](https://avatars.discourse-cdn.com/v4/letter/j/a6a055/32.png) [@juanaramis](https://discuss.elastic.co/u/juanaramis)\
**Post date:** [July 18, 2018, 8:08pm UTC](https://discuss.elastic.co/t/bulkprocessor-creation-using-resthighlevelclient-compilation-error-on-es5-6/140573/3 "2018-07-18T20:08:42Z")

</div>

Hi Rappahannock,

That is a eclipse bug: [https://bugs.eclipse.org/bugs/show\_bug.cgi?id=514884](https://bugs.eclipse.org/bugs/show_bug.cgi?id=514884)

I just write the code this way with try with resource:

```
try (final BulkProcessor bulkProcessor = new BulkProcessor.Builder(restHighLevelClient::bulkAsync,//<--- See BUG https://bugs.eclipse.org/bugs/show_bug.cgi?id=514884
                                                                     getBulkProcessorListener(),
                                                                     new ThreadPool(Settings.builder().put(Node.NODE_NAME_SETTING.getKey(), "high-level-client").build()))
                                                            .setConcurrentRequests(props.getConcurrentRequests())
                                                            .setBulkSize(new ByteSizeValue(props.getBulkSize(), ByteSizeUnit.MB))
                                                            .setBulkActions(props.getBulkActions())
                                                            .setFlushInterval(TimeValue.timeValueSeconds(props.getFlushIntervalSeconds()))
                                                            .setBackoffPolicy(BackoffPolicy.exponentialBackoff(TimeValue.timeValueMillis(props.getConnectionRequestTimeOut() * 1000), props.getMaxNumberOfRetry()))
                                                            .build())
        {

```

....

Try it, and please let me know if that solved your issue.

Juan Cobas

---

<div class="post-metadata">

**Author:** ![Rappahannock](https://avatars.discourse-cdn.com/v4/letter/r/dc4da7/32.png) [@Rappahannock](https://discuss.elastic.co/u/Rappahannock)\
**Post date:** [July 19, 2018, 9:35am UTC](https://discuss.elastic.co/t/bulkprocessor-creation-using-resthighlevelclient-compilation-error-on-es5-6/140573/4 "2018-07-19T09:35:10Z")

</div>

Hi juanaramis,

Thank you for your input.

As I mentioned in my previous comment, I don't use Eclipse, I compile in another IDE and from command line. So I don't think it can be Eclipse bug.

But your piece of code is helpful anyway, because it works!  
But actually you don't need 'try with resource' for it to work.

The following piece of code works fine too:

```auto
        BulkProcessor bulkProcessor = new BulkProcessor.Builder(
                             restHighLevelClient::bulkAsync,
                             new BulkProcessorListener(),
                             new ThreadPool(Settings.builder().put(Node.NODE_NAME_SETTING.getKey(), "high-level-client").build()))
                                .setBulkActions(bulkActionsCount)
                                .build();

```

The only difference with my original code here is that I need to supply ThreadPool by myself, which so far I didn't want to do.

---

<div class="post-metadata">

**Author:** ![Rappahannock](https://avatars.discourse-cdn.com/v4/letter/r/dc4da7/32.png) [@Rappahannock](https://discuss.elastic.co/u/Rappahannock)\
**Post date:** [July 19, 2018, 9:37am UTC](https://discuss.elastic.co/t/bulkprocessor-creation-using-resthighlevelclient-compilation-error-on-es5-6/140573/5 "2018-07-19T09:37:28Z")

</div>

Here is a part from BulkProcessor code from ES6.2.4 which is not yet in v5.6.6

```auto
    public static BulkProcessor.Builder builder(BiConsumer<BulkRequest, ActionListener<BulkResponse>> consumer, BulkProcessor.Listener listener) {
        Objects.requireNonNull(consumer, "consumer");
        Objects.requireNonNull(listener, "listener");
        ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = Scheduler.initScheduler(Settings.EMPTY);
        return new BulkProcessor.Builder(consumer, listener, (delay, executor, command) -> {
            return scheduledThreadPoolExecutor.schedule(command, delay.millis(), TimeUnit.MILLISECONDS);
        }, () -> {
            Scheduler.terminate(scheduledThreadPoolExecutor, 10L, TimeUnit.SECONDS);
        }, null);
    }

```

So I guess this is what makes my original code work on ES6.2.4.

```auto
BulkProcessor bulkProcessor = BulkProcessor.builder(restHighLevelClient::bulkAsync, listener).build();

```

But I cannot create threadPool the same way, because class Scheduler doesn't exist in v5.6.6.  
So I think I need to dig into code of threadPool creation in ES6.2.4 to understand how can I create it in similar way and use this code on ES5.6.6

```auto
        BulkProcessor bulkProcessor =
            new BulkProcessor.Builder(restHighLevelClient::bulkAsync, new BulkProcessorListener(), threadPool)
                .setBulkActions(bulkActionsCount)
                .build();

```

---

<div class="post-metadata">

**Author:** ![Rappahannock](https://avatars.discourse-cdn.com/v4/letter/r/dc4da7/32.png) [@Rappahannock](https://discuss.elastic.co/u/Rappahannock)\
**Post date:** [July 19, 2018, 2:09pm UTC](https://discuss.elastic.co/t/bulkprocessor-creation-using-resthighlevelclient-compilation-error-on-es5-6/140573/6 "2018-07-19T14:09:47Z")

</div>

I found these related issues:

> <https://github.com/elastic/elasticsearch/issues/26028>

  

> <https://github.com/elastic/elasticsearch/pull/26727>

So I came to a conclusion, that is a good solution for v.5.6.6 to use the following code

```auto
BulkProcessor bulkProcessor = new BulkProcessor.Builder(
            restHighLevelClient::bulkAsync, new BulkProcessorListener(),
            new ThreadPool(Settings.builder().put(Node.NODE_NAME_SETTING.getKey(), "high-level-client").build()))
            .setBulkActions(bulkActionsCount)
            .build();

```

@juanaramis, thanks again for the hint.

---

<div class="post-metadata">

**Author:** ![juanaramis](https://avatars.discourse-cdn.com/v4/letter/j/a6a055/32.png) [@juanaramis](https://discuss.elastic.co/u/juanaramis)\
**Post date:** [July 19, 2018, 7:14pm UTC](https://discuss.elastic.co/t/bulkprocessor-creation-using-resthighlevelclient-compilation-error-on-es5-6/140573/7 "2018-07-19T19:14:49Z")

</div>

You are welcome 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 16, 2018, 7:14pm UTC](https://discuss.elastic.co/t/bulkprocessor-creation-using-resthighlevelclient-compilation-error-on-es5-6/140573/8 "2018-08-16T19:14:52Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
