Recently i am writing the mapper for pushing data to elasticsearch. My input is avro object where i am trying to convert to Json. Every thing is fine but i am getting namespace in json, where elasticsearch wont allow namespace as key objects.
"requestobj":{"com.nw.data.Request":{"event_id":null,"event_epoch":-1,"event_dispatch_epoch":-1,"server_epoch":1471852915279,"date":{"string":"2016-08-22"},"time":{"string":"08:01:55"},"req_source":{"string":"app"},"req_channel":{"string":"Mobile"},"req_dimension":{"string":"1312x704"}
is there a way to exclude namespace - com.nw.data.Request
I am using following code to convert avro to json:
public static String getJsonString(GenericRecord record) throws IOException {
ByteArrayOutputStream os = new ByteArrayOutputStream();
JsonEncoder encoder = EncoderFactory.get().jsonEncoder(record.getSchema(), os);
DatumWriter<GenericRecord> writer = new GenericDatumWriter<GenericRecord>(record.getSchema());
writer.setSchema(record.getSchema());
writer.write(record, encoder);
encoder.flush();
String jsonString = new String(os.toByteArray(), Charset.forName("UTF-8"));
os.close();
return jsonString;
}
Following Juan's PR being merged, you can now use
encoder.setIncludeNamespace(false);