The official Elasticsearch docs tell to instantiate ElasticsearchClient
like this:
ElasticsearchClient client = new ElasticsearchClient(transport);
Once I write this in my Grails 3 application with Gradle build management, I get the following compilation error: Cannot instantiate interface 'ElasticsearchClient'
The import
statement is: import org.elasticsearch.client.ElasticsearchClient
.
Indeed, ElasticsearchClient
gets resolved to:
package org.elasticsearch.client;
// ...
public interface ElasticsearchClient {
The Gradle dependency is: compile 'org.elasticsearch:elasticsearch:7.17.2'
The reason for this was: ElasticsearchClient
was mis-resolved to an old elasticsearch JAR file that had still been in my local user's .gradle
directory. Removing the old JAR from .gradle
enabled me to do the correct import.
The correct import is
import co.elastic.clients.elasticsearch.ElasticsearchClient
instead of
import org.elasticsearch.client.ElasticsearchClient