@Override public String[] names() {
return new String[]{NAME, Strings.toCamelCase(NAME)};
}
@Override public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
XContentParser parser = parseContext.parser();
Query query = null;
float boost = 1.0f;
float boostFactor = 1.0f;
String currentFieldName = null;
XContentParser.Token token;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token == XContentParser.Token.START_OBJECT) {
if ("query".equals(currentFieldName)) {
query = parseContext.parseInnerQuery();
}
} else if (token.isValue()) {
if ("boost_factor".equals(currentFieldName) || "boostFactor".equals(currentFieldName)) {
boostFactor = parser.floatValue();
} else if ("boost".equals(currentFieldName)) {
boost = parser.floatValue();
}
}
}
if (query == null) {
throw new QueryParsingException(parseContext.index(), "[constant_factor_query] requires 'query' element");