Hi,
I am working on a task which required to have an array of nested Index
for a field, the mapping of which is given below
"eventnested":{
"type" : "nested", "store" : "yes", "index" : "analyzed",
"omit_norms" : "true",
"include_in_parent":true,
"properties":{
"event_type":{"type" : "string", "store" : "yes", "index" :
"not_analyzed", "omit_norms" : "true"},
"attributes":{
"properties":{
"event_attribute_name":{"type" : "string", "store" : "yes",
"index" : "not_analyzed", "omit_norms" : "true"},
"event_attribute_value":{"type" : "string", "store" : "yes",
"index" : "not_analyzed", "omit_norms" : "true"}
}
},
"event_attribute_instance":{"type" : "string", "store" : "yes",
"precision_step" : "0"}
}
}
I tried indexing data using a Curl with this mapping, which worked.
But when I tried the same using Java API, the data was indexed
wrong(unreadable). I have given below the snippet of the code I
followed
XContentBuilder xb1 = XContentFactory.jsonBuilder().startObject();
XContentBuilder xb2 = XContentFactory.jsonBuilder().startObject();
xb1.startArray("eventnested");
for(int j=0;j<2;j++)
{
xb2.field("event_type",eventType);
xb2.field("event_attribute_instance",eventInstance);
xb2.startArray("attributes");
for(int i=0;i<2;i++)
{
XContentBuilder xb3 = XContentFactory.jsonBuilder().startObject();
xb3.field("event_attribute_name", attrName);
xb3.field("event_attribute_value", attrValue);
xb2.value(xb3.copiedBytes());
}
xb1.value(xb2.copiedBytes());
}
After indexing the data, when I read the response the data of the
particular field looked like
"eventnested.event_type":
["eyJldmVudF90eXBlIjoiUXVvdGF0aW9uIiwiZXZlbnRfYXR0cmlidXRlX2luc3RhbmNlIjoiMSIsImF0dHJpYnV0ZXMiOlsiZXlKbGRtVnVkRjloZEhSeWFXSjFkR1ZmYm1GdFpTSTZJbkJsY25OdmJpQWlMQ0psZG1WdWRGOWhkSFJ5YVdKMWRHVmZkbUZzZFdVaU9pSkxZWGtnVFdGcmFIVmlaV3hoSW4wPSJdLCJhdHRyaWJ1dGVzIjpbImV5SmxkbVZ1ZEY5aGRIUnlhV0oxZEdWZmJtRnRaU0k2SW5GMWIzUmxJQ0lzSW1WMlpXNTBYMkYwZEhKcFluVjBaV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