Hi,
I am facing issues while retrieving stored fields from Elasticsearch using java client.
- creating template:
PUT _index_template/test_tf_template
{
"index_patterns": ["test-tf-*"],
"template": {
"mappings": {
"_source": {
"excludes": ["inference"]
},
"properties": {
"inference": {
"type": "text",
"store": true
}
}
}
}
}
- indexing a document via kibana
POST test-tf-index/_create/ds1
{
"name": "ds-1",
"inference": "sample text"
}
- retrieving stored fields via kibana (works with no issues)
GET test-tf-index/_search
{
"_source": ["*"],
"stored_fields": ["inference"]
}
- Tried doing the same with java, but getting parser exception.
String indexName = "test-tf-index";
SearchRequest request = SearchRequest.of(s -> s.index(indexName)
.source(sc -> sc.filter(v -> v.includes(List.of("name"))))
.storedFields(List.of("inference"))
);
SearchResponse<Map> response= client.search(request, Map.class);
System.out.println("response : " + response);
Exception Trace:
jakarta.json.stream.JsonGenerationException: Illegal method during JSON generation, not valid in current context IN_OBJECT
at org.eclipse.parsson.JsonGeneratorImpl.checkContextForValue(JsonGeneratorImpl.java:405)
at org.eclipse.parsson.JsonGeneratorImpl.write(JsonGeneratorImpl.java:357)
at co.elastic.clients.json.JsonpUtils.copy(JsonpUtils.java:186)
at co.elastic.clients.json.JsonpUtils.copy(JsonpUtils.java:180)
at co.elastic.clients.json.JsonpUtils.copy(JsonpUtils.java:157)
at co.elastic.clients.json.jackson.JacksonJsonBuffer.serialize(JacksonJsonBuffer.java:98)
at co.elastic.clients.elasticsearch.core.search.Hit.serializeInternal(Hit.java:319)
at co.elastic.clients.elasticsearch.core.search.Hit.serialize(Hit.java:293)
at co.elastic.clients.elasticsearch.core.search.HitsMetadata.serializeInternal(HitsMetadata.java:130)
at co.elastic.clients.elasticsearch.core.search.HitsMetadata.serialize(HitsMetadata.java:115)
at co.elastic.clients.elasticsearch.core.search.ResponseBody.serializeInternal(ResponseBody.java:248)
at co.elastic.clients.elasticsearch.core.search.ResponseBody.serialize(ResponseBody.java:232)
at co.elastic.clients.json.JsonpUtils.toString(JsonpUtils.java:409)
at co.elastic.clients.json.JsonpUtils.toString(JsonpUtils.java:346)
at co.elastic.clients.elasticsearch.core.search.ResponseBody.toString(ResponseBody.java:311)
at java.base/java.lang.StringConcatHelper.stringOf(StringConcatHelper.java:453)
at java.base/java.lang.StringConcatHelper.simpleConcat(StringConcatHelper.java:408)
.....
Suppressed: jakarta.json.stream.JsonGenerationException: Generating incomplete JSON
at org.eclipse.parsson.JsonGeneratorImpl.close(JsonGeneratorImpl.java:519)
at co.elastic.clients.json.JsonpUtils.toString(JsonpUtils.java:408)
... 6 more
Elastic Search v8.9.0
Java client 8.8.1
Please let me know if there is a way to fix this or if I missed something.
Thank you.