Description: I have to read a particular field from Elasticsearch 5.4 using Apache camel. When I use the below code, I'm not able to view the response
Exception: Error building toString out of XContent: com.fasterxml.jackson.core.JsonGenerationException: Can not start an object, expecting field name (context: Object)
Code:
from("direct:start")
.process(exchange -> {
GetRequest a = new GetRequest("example", "doc", "1");
exchange.getIn().setBody(a);
})
.to("elasticsearch5://elastic?operation=GET_BY_ID&ip=<ip>&port=9300")
.log("${body}");
Complete Stacktrace:
(route1) elasticsearch5://elastic?ip=&operation=GET_BY_ID&port=9300 --> log[messageId] <<< Pattern:InOnly, Headers:{breadcrumbId=ID-NLVHPRAAB02027-53300-1510315731625-0-1}, BodyType:org.elasticsearch.action.support.PlainActionFuture, Body:Error building toString out of XContent: com.fasterxml.jackson.core.JsonGenerationException: Can not start an object, expecting field name (context: Object) at com.fasterxml.jackson.core.JsonGenerator._reportError(JsonGenerator.java:1897) at com.fasterxml.jackson.core.json.JsonGeneratorImpl._reportCantWriteValueExpectName(JsonGeneratorImpl.java:244) at com.fasterxml.jackson.core.json.UTF8JsonGenerator._verifyValueWrite(UTF8JsonGenerator.java:1033) at com.fasterxml.jackson.core.json.UTF8JsonGenerator.writeStartObject(UTF8JsonGenerator.java:313) at org.elasticsearch.common.xcontent.json.JsonXContentGenerator.writeStartObject(JsonXContentGenerator.java:161) at org.elasticsearch.common.xcontent.XContentBuilder.startObject(XContentBuilder.java:217) at org.elasticsearch.index.get.GetResult.toXContent(GetResult.java:251) at org.elasticsearch.action.get.GetResponse.toXContent(GetResponse.java:158) at org.elasticsearch.common.Strings.toString(Strings.java:901) at org.elastic... [Body clipped after 1000 chars, total length is 4350]
Are you using the camel-elasticsearch5 component? In that case you need to do something like this: