[JAVA] Unexpected JSON event 'VALUE_TRUE' instead of '[KEY_NAME, VALUE_STRING]'

I am writing some code to manage Elasticsearch templates. When running the code snippet below I am getting

co.elastic.clients.json.UnexpectedJsonEventException: Unexpected JSON event 'VALUE_FALSE' instead of '[KEY_NAME, VALUE_STRING]'

Code

// simplified code for demo this issue, but does reproduce.
private static stackoverflowIssue(ElasticsearchClient client) {
  GetIndexTemplateResponse r = client.indices().getIndexTemplate();
}

ES info:

{
  "name" : "1ec11a1cb3c9",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "7e0zLYxmQsST0EllSlc_KA",
  "version" : {
    "number" : "7.16.2",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "2b937c44140b6559905130a8650c64dbd0879cfb",
    "build_date" : "2021-12-18T19:42:46.604893745Z",
    "build_snapshot" : false,
    "lucene_version" : "8.10.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

ES dependency in pom.xml

        <dependency>
            <groupId>co.elastic.clients</groupId>
            <artifactId>elasticsearch-java</artifactId>
            <version>7.16.3</version>
        </dependency>

        <dependency>
            <groupId>jakarta.json</groupId>
            <artifactId>jakarta.json-api</artifactId>
            <version>2.0.1</version>
        </dependency>

Please help, Thanks!

Full callstack

Caused by: co.elastic.clients.json.UnexpectedJsonEventException: Unexpected JSON event 'VALUE_TRUE' instead of '[KEY_NAME, VALUE_STRING]'
	at co.elastic.clients.json.JsonpUtils.ensureAccepts(JsonpUtils.java:68) ~[elasticsearch-java-7.16.3.jar:na]
JsonpUtils.java:68
	at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:74) ~[elasticsearch-java-7.16.3.jar:na]
JsonpDeserializer.java:74
	at co.elastic.clients.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:72) ~[elasticsearch-java-7.16.3.jar:na]
ObjectDeserializer.java:72
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:176) ~[elasticsearch-java-7.16.3.jar:na]
ObjectDeserializer.java:176
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:137) ~[elasticsearch-java-7.16.3.jar:na]
ObjectDeserializer.java:137
	at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:75) ~[elasticsearch-java-7.16.3.jar:na]
JsonpDeserializer.java:75
	at co.elastic.clients.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:79) ~[elasticsearch-java-7.16.3.jar:na]
ObjectBuilderDeserializer.java:79
	at co.elastic.clients.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:43) ~[elasticsearch-java-7.16.3.jar:na]
DelegatingDeserializer.java:43
	at co.elastic.clients.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:72) ~[elasticsearch-java-7.16.3.jar:na]
ObjectDeserializer.java:72
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:176) ~[elasticsearch-java-7.16.3.jar:na]
ObjectDeserializer.java:176
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:137) ~[elasticsearch-java-7.16.3.jar:na]
ObjectDeserializer.java:137
	at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:75) ~[elasticsearch-java-7.16.3.jar:na]
JsonpDeserializer.java:75
	at co.elastic.clients.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:79) ~[elasticsearch-java-7.16.3.jar:na]
ObjectBuilderDeserializer.java:79
	at co.elastic.clients.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:43) ~[elasticsearch-java-7.16.3.jar:na]
DelegatingDeserializer.java:43
	at co.elastic.clients.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:72) ~[elasticsearch-java-7.16.3.jar:na]
ObjectDeserializer.java:72
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:176) ~[elasticsearch-java-7.16.3.jar:na]
ObjectDeserializer.java:176
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:137) ~[elasticsearch-java-7.16.3.jar:na]
ObjectDeserializer.java:137
	at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:75) ~[elasticsearch-java-7.16.3.jar:na]
JsonpDeserializer.java:75
	at co.elastic.clients.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:79) ~[elasticsearch-java-7.16.3.jar:na]
ObjectBuilderDeserializer.java:79
	at co.elastic.clients.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:43) ~[elasticsearch-java-7.16.3.jar:na]
DelegatingDeserializer.java:43
	at co.elastic.clients.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:72) ~[elasticsearch-java-7.16.3.jar:na]
ObjectDeserializer.java:72
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:176) ~[elasticsearch-java-7.16.3.jar:na]
ObjectDeserializer.java:176
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:137) ~[elasticsearch-java-7.16.3.jar:na]
ObjectDeserializer.java:137
	at co.elastic.clients.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:85) ~[elasticsearch-java-7.16.3.jar:na]
ObjectBuilderDeserializer.java:85
	at co.elastic.clients.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:48) ~[elasticsearch-java-7.16.3.jar:na]
DelegatingDeserializer.java:48
	at co.elastic.clients.json.JsonpDeserializerBase$ArrayDeserializer.deserialize(JsonpDeserializerBase.java:320) ~[elasticsearch-java-7.16.3.jar:na]
JsonpDeserializerBase.java:320
	at co.elastic.clients.json.JsonpDeserializerBase$ArrayDeserializer.deserialize(JsonpDeserializerBase.java:285) ~[elasticsearch-java-7.16.3.jar:na]
JsonpDeserializerBase.java:285
	at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:75) ~[elasticsearch-java-7.16.3.jar:na]
JsonpDeserializer.java:75
	at co.elastic.clients.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:72) ~[elasticsearch-java-7.16.3.jar:na]
ObjectDeserializer.java:72
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:176) ~[elasticsearch-java-7.16.3.jar:na]
ObjectDeserializer.java:176
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:137) ~[elasticsearch-java-7.16.3.jar:na]
	at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:75) ~[elasticsearch-java-7.16.3.jar:na]
JsonpDeserializer.java:75
	at co.elastic.clients.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:79) ~[elasticsearch-java-7.16.3.jar:na]
ObjectBuilderDeserializer.java:79
	at co.elastic.clients.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:43) ~[elasticsearch-java-7.16.3.jar:na]
DelegatingDeserializer.java:43
	at co.elastic.clients.transport.rest_client.RestClientTransport.decodeResponse(RestClientTransport.java:325) ~[elasticsearch-java-7.16.3.jar:na]
RestClientTransport.java:325
	at co.elastic.clients.transport.rest_client.RestClientTransport.getHighLevelResponse(RestClientTransport.java:291) ~[elasticsearch-java-7.16.3.jar:na]
RestClientTransport.java:291
	at co.elastic.clients.transport.rest_client.RestClientTransport.performRequest(RestClientTransport.java:144) ~[elasticsearch-java-7.16.3.jar:na]
RestClientTransport.java:144
	at co.elastic.clients.elasticsearch.indices.ElasticsearchIndicesClient.getIndexTemplate(ElasticsearchIndicesClient.java:1097) ~[elasticsearch-java-7.16.3.jar:na]

Thanks for the report. Can you provide the result of calling GET /_index_template on your Elasticsearch cluster (redact any sensitive string if needed)? That will help us find the cause.

The output is too long to paste here.

See GET _index_template - Pastebin

@wxh Typically folks use pastebin or a gist to post results/ code / logs etc makes it easier for those trying to help.

Perhaps you could use one of those... That long encoded string is unwieldy :slight_smile:

Sure. I've updated my previous reply with a link to pastebin.

1 Like

Which Java Client are you using...

This does not look like the new Java Client Here (Corrected)

Looks like the Deprecated Version Here (Incorrect)

On the deprecated version

Seems like you are missing the argument for the name of the template

GetIndexTemplatesRequest request = new GetIndexTemplatesRequest("my-template"); 
request = new GetIndexTemplatesRequest("template-1", "template-2"); 
request = new GetIndexTemplatesRequest("my-*"); 

Or is that too easy... :slight_smile:

BTW I took a quick look at the result of the GET /_index_template and I did not see anything as a glaring issue.

The getIndexTemplate() method implementation can be found at

Is that the deprecate version?

Nope You have the correct version.... apologies for the confusion...
That is the new Elasticsearch Java API Client

Hmm I think we will need some help from @swallez

And BTW Welcome to the community.

Thanks. I recently picked up Elasticsearch again since I dropped in 2 years ago. A lot changes have happened.

Anyway, I just came up with a minimal Maven project to demo the issue.

(not a fan of dropbox or gdrive, so base64 encoded tarball again. :slight_smile: )

Run the maven project you will get the exact error message with exact callstack in the first post.

$ mvn spring-boot:run
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] >>> spring-boot-maven-plugin:2.5.9:run (default-cli) > test-compile @ demo >>>
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory /home/opc/junk/demo/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] <<< spring-boot-maven-plugin:2.5.9:run (default-cli) < test-compile @ demo <<<
[INFO] 
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.5.9:run (default-cli) @ demo ---
[INFO] Attaching agents: []

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.5.9)

2022-01-29 23:41:00.414  INFO 649221 --- [           main] com.example.demo.Demo                    : Starting Demo using Java 1.8.0_311 on cloudberry-2 with PID 649221 (/home/opc/junk/demo/target/classes started by opc in /home/opc/junk/demo)
2022-01-29 23:41:00.416  INFO 649221 --- [           main] com.example.demo.Demo                    : No active profile set, falling back to default profiles: default
2022-01-29 23:41:01.136  WARN 649221 --- [           main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'service' defined in file [/home/opc/junk/demo/target/classes/com/example/demo/Service.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.example.demo.Service]: Constructor threw exception; nested exception is co.elastic.clients.json.UnexpectedJsonEventException: Unexpected JSON event 'VALUE_TRUE' instead of '[KEY_NAME, VALUE_STRING]'
2022-01-29 23:41:01.144  INFO 649221 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-01-29 23:41:01.157 ERROR 649221 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'service' defined in file [/home/opc/junk/demo/target/classes/com/example/demo/Service.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.example.demo.Service]: Constructor threw exception; nested exception is co.elastic.clients.json.UnexpectedJsonEventException: Unexpected JSON event 'VALUE_TRUE' instead of '[KEY_NAME, VALUE_STRING]'
        at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:315) ~[spring-beans-5.3.15.jar:5.3.15]
        at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:296) ~[spring-beans-5.3.15.jar:5.3.15]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1372) ~[spring-beans-5.3.15.jar:5.3.15]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1222) ~[spring-beans-5.3.15.jar:5.3.15]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.15.jar:5.3.15]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.15.jar:5.3.15]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.15.jar:5.3.15]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.15.jar:5.3.15]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.15.jar:5.3.15]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.15.jar:5.3.15]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) ~[spring-beans-5.3.15.jar:5.3.15]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.15.jar:5.3.15]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.15.jar:5.3.15]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767) [spring-boot-2.5.9.jar:2.5.9]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:447) [spring-boot-2.5.9.jar:2.5.9]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) [spring-boot-2.5.9.jar:2.5.9]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1356) [spring-boot-2.5.9.jar:2.5.9]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1345) [spring-boot-2.5.9.jar:2.5.9]
        at com.example.demo.Demo.main(Demo.java:10) [classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.example.demo.Service]: Constructor threw exception; nested exception is co.elastic.clients.json.UnexpectedJsonEventException: Unexpected JSON event 'VALUE_TRUE' instead of '[KEY_NAME, VALUE_STRING]'
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:224) ~[spring-beans-5.3.15.jar:5.3.15]
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:117) ~[spring-beans-5.3.15.jar:5.3.15]
        at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:311) ~[spring-beans-5.3.15.jar:5.3.15]
        ... 18 common frames omitted
Caused by: co.elastic.clients.json.UnexpectedJsonEventException: Unexpected JSON event 'VALUE_TRUE' instead of '[KEY_NAME, VALUE_STRING]'
        at co.elastic.clients.json.JsonpUtils.ensureAccepts(JsonpUtils.java:68) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:74) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:72) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:176) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:137) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:75) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:79) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:43) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:72) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:176) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:137) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:75) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:79) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:43) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:72) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:176) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:137) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:75) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:79) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:43) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:72) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:176) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:137) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:85) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:48) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.JsonpDeserializerBase$ArrayDeserializer.deserialize(JsonpDeserializerBase.java:320) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.JsonpDeserializerBase$ArrayDeserializer.deserialize(JsonpDeserializerBase.java:285) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:75) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:72) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:176) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:137) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:75) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:79) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:43) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.transport.rest_client.RestClientTransport.decodeResponse(RestClientTransport.java:325) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.transport.rest_client.RestClientTransport.getHighLevelResponse(RestClientTransport.java:291) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.transport.rest_client.RestClientTransport.performRequest(RestClientTransport.java:144) ~[elasticsearch-java-7.16.3.jar:na]
        at co.elastic.clients.elasticsearch.indices.ElasticsearchIndicesClient.getIndexTemplate(ElasticsearchIndicesClient.java:1126) ~[elasticsearch-java-7.16.3.jar:na]
        at com.example.demo.Service.<init>(Service.java:16) ~[classes/:na]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_311]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_311]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_311]
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_311]
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:211) ~[spring-beans-5.3.15.jar:5.3.15]
        ... 20 common frames omitted

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.246 s
[INFO] Finished at: 2022-01-29T23:41:01Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.5.9:run (default-cli) on project demo: Application finished with exit code: 1 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

I also managed to repro this with 5 lines of code:

        ObjectMapper om = new ObjectMapper();
        Response r = restClient.performRequest(new Request("GET", "_index_template"));
        JsonParser parser = new JacksonJsonpParser(om.createParser(r.getEntity().getContent()));
        JsonpMapper mapper = new JacksonJsonpMapper();
        GetIndexTemplateResponse._DESERIALIZER.deserialize(parser, mapper); // <-- boom!

I was able to reproduce it from the pastebin output (thanks for providing it!) and decoding it as follows:

InputStream is = this.getClass().getResourceAsStream("discuss-295740.json");
JsonParser parser = mapper.jsonProvider().createParser(is);
try {
    JsonpDeserializer.of(GetIndexTemplateResponse.class).deserialize(parser, mapper);
} catch(UnexpectedJsonEventException e) {
    JsonLocation loc = e.getLocation();
    fail(loc.getLineNumber() + ":" + loc.getColumnNumber());
}

The result is 419:29, which points to:

"mappings" : {
   ...
   "dynamic" : true, // <-- line 419
   "dynamic_templates" : [ ],
   ...

This is an incarnation of this isssue on read rather than on write: Serialize DynamicMapping values as booleans instead of string · Issue #139 · elastic/elasticsearch-java · GitHub

Please watch that issue for resolution.

2 Likes

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