I am trying to build and add a new map to an ES index through Java. But for some reason, the ES server is not accepting my syntax. Here's the code:
XContentBuilder jsonBuilder =
XContentFactory.contentBuilder(XContentType.JSON);
jsonBuilder.startObject();
jsonBuilder.startObject(name);
jsonBuilder.startObject("properties");
for (FieldDesc<?> desc : fields) {
// Do stuff to build the field objects
}
jsonBuilder.endObject();
jsonBuilder.endObject();
jsonBuilder.endObject();
System.out.println(jsonBuilder.string());
System.out.flush();
PutMappingRequest putMap = new PutMappingRequest(index);
putMap.source(jsonBuilder);
client.admin().indices().putMapping(putMap).actionGet();
The JSON string that is printed out resembles the following (formatted for readability):
{"status":
{"properties":
{"Transaction_ID":{"type":"long","store":"yes"},
"IP_Address":{"type":"string","store":"yes"},
"Machine Type":{"type":"string","index":"not_analyzed","store":"yes"},
...
}}}
The error I get is the following:
Exception in thread "main" org.elasticsearch.action.ActionRequestValidationException: Validation Failed: 1: mapping type is missing;
at org.elasticsearch.action.ValidateActions.addValidationError(ValidateActions.java:29)
at org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest.validate(PutMappingRequest.java:80)
at org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:55)
What am I doing wrong? Any help would be deeply appreciated. Thanks