if ("params".equals(fieldName)) {
params = parser.map();
} else if ("facet".equals(fieldName)) {
token = parser.nextToken();
if (token != XContentParser.Token.FIELD_NAME)
throw new FacetPhaseExecutionException(facetName, "No facet type defined under facet node");
String facetType = parser.currentName();
internalProcessor = processors.processor(facetType);
if (internalProcessor == null) {
throw new FacetPhaseExecutionException(facetName, "No facet type found for [" + facetType + "]");
}
;
// Store underlying facet configuration
token = parser.nextToken(); // move the start of object...
ByteArrayOutputStream memstream = new ByteArrayOutputStream(20);
XContentGenerator generator = new JsonXContentGenerator(jsonFactory.createJsonGenerator(memstream));
XContentHelper.copyCurrentStructure(generator, parser);
generator.close();
memstream.close();
internalConfig = memstream.toByteArray(); // now we're at the end of the underlying config.
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT); // eat everything else under the "facet" clause
}
}
else if (token.isValue()) {
if ("field".equals(fieldName)) {
keyField = parser.text();
} else if ("key_field".equals(fieldName)) {
keyField = parser.text();
} else if ("interval".equals(fieldName)) {
interval = parser.text();
} else if ("time_zone".equals(fieldName) || "timeZone".equals(fieldName)) {
preZone = parseZone(parser, token);
} else if ("pre_zone".equals(fieldName) || "preZone".equals(fieldName)) {
preZone = parseZone(parser, token);
} else if ("pre_zone_adjust_large_interval".equals(fieldName) || "preZoneAdjustLargeInterval".equals(fieldName)) {
preZoneAdjustLargeInterval = parser.booleanValue();
} else if ("post_zone".equals(fieldName) || "postZone".equals(fieldName)) {
postZone = parseZone(parser, token);
} else if ("pre_offset".equals(fieldName) || "preOffset".equals(fieldName)) {
preOffset = parseOffset(parser.text());
} else if ("post_offset".equals(fieldName) || "postOffset".equals(fieldName)) {
postOffset = parseOffset(parser.text());
} else if ("factor".equals(fieldName)) {
factor = parser.floatValue();
}
}
}
if (keyField == null) {
throw new FacetPhaseExecutionException(facetName, "key field is required to be set for histogram facet, either using [field] or using [key_field]");
}
FieldMapper mapper = context.smartNameFieldMapper(keyField);
if (mapper == null) {
throw new FacetPhaseExecutionException(facetName, "(key) field [" + keyField + "] not found");
}
if (mapper.fieldDataType() != FieldDataType.DefaultTypes.LONG) {
throw new FacetPhaseExecutionException(facetName, "(key) field [" + keyField + "] is not of type date");
}
if (interval == null) {
throw new FacetPhaseExecutionException(facetName, "[interval] is required to be set for histogram facet");
}
if (internalProcessor == null) {
throw new FacetPhaseExecutionException(facetName, "faceted histogram misses an internal facet definition.");
}
TimeZoneRounding.Builder tzRoundingBuilder;
DateFieldParser fieldParser = dateFieldParsers.get(interval);
if (fieldParser != null) {