I am attempting to create an index as follows:
public class CreateIndexTest {
@Test
public void testIndexCreationWithMapping() throws IOException {
final RestClientBuilder restClientBuilder =
RestClient.builder(new HttpHost("localhost", 9200));
final RestHighLevelClient esClient =
new RestHighLevelClient(restClientBuilder);
String indexName = "students";
String typeName = "student";
final CreateIndexRequest createIndexRequest =
new CreateIndexRequest(
indexName
)
;
createIndexRequest.settings(
Settings.builder()
.put("index.number_of_shards", 1)
.put("index.number_of_replicas", 1)
);
final String mapping =
"{" +
" \"mappings\": {" +
" \"student\": {" +
" \"properties\": {" +
" \"student_id\": {" +
" \"type\": \"long\"" +
" }" +
" }" +
" }" +
" }" +
"}"
;
createIndexRequest.mapping(typeName, mapping, XContentType.JSON);
esClient.indices().create(createIndexRequest);
}
}
But this results in the following exception (in create() call on the last line of the snippet above):
java.lang.NoSuchMethodError: org.elasticsearch.action.admin.indices.create.CreateIndexResponse.fromXContent(Lorg/elasticsearch/common/xcontent/XContentParser;)Lorg/elasticsearch/action/admin/indices/create/CreateIndexResponse;
at java.base/java.lang.invoke.MethodHandleNatives.resolve(Native Method)
at java.base/java.lang.invoke.MemberName$Factory.resolve(MemberName.java:1041)
at java.base/java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:1066)
at java.base/java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:2040)
at java.base/java.lang.invoke.MethodHandles$Lookup.linkMethodHandleConstant(MethodHandles.java:2453)
at java.base/java.lang.invoke.MethodHandleNatives.linkMethodHandleConstant(MethodHandleNatives.java:501)
at org.elasticsearch.client.IndicesClient.create(IndicesClient.java:77)
at x.CreateIndexTest.testIndexCreationWithMapping(CreateIndexTest.java:49)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
I am using elasticsearch-rest-high-level-client version 6.2.4
compile('org.elasticsearch.client:elasticsearch-rest-high-level-client:6.2.4')
with a server of the same version:
$ curl localhost:9200/
{
"name" : "SNDFUfO",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "ZffUtr4PQxaU2aMdaCEZnQ",
"version" : {
"number" : "6.2.4",
"build_hash" : "ccec39f",
"build_date" : "2018-04-12T20:37:28.497551Z",
"build_snapshot" : false,
"lucene_version" : "7.2.1",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
Java version is 9.0:
$ java -version
openjdk version "9.0.4"
OpenJDK Runtime Environment (build 9.0.4+11)
OpenJDK 64-Bit Server VM (build 9.0.4+11, mixed mode)
Appreciate any pointers on what I could be doing wrong.
Note: This question also pertains to this same exception, but version incompatibility was the issue there. In my case, the client and server are the same version.