use of org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction in project elasticsearch by elastic.
the class DiversifiedSamplerTests method testCase.
private void testCase(IndexSearcher indexSearcher, MappedFieldType genreFieldType, String executionHint, Consumer<InternalSampler> verify) throws IOException {
MappedFieldType idFieldType = new KeywordFieldMapper.KeywordFieldType();
idFieldType.setName("id");
idFieldType.setHasDocValues(true);
SortedNumericDVIndexFieldData fieldData = new SortedNumericDVIndexFieldData(new Index("index", "index"), "price", IndexNumericFieldData.NumericType.DOUBLE);
FunctionScoreQuery query = new FunctionScoreQuery(new MatchAllDocsQuery(), new FieldValueFactorFunction("price", 1, FieldValueFactorFunction.Modifier.RECIPROCAL, null, fieldData));
DiversifiedAggregationBuilder builder = new DiversifiedAggregationBuilder("_name").field(genreFieldType.name()).executionHint(executionHint).subAggregation(new TermsAggregationBuilder("terms", null).field("id"));
InternalSampler result = search(indexSearcher, query, builder, genreFieldType, idFieldType);
verify.accept(result);
}
use of org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction in project elasticsearch by elastic.
the class FieldValueFactorFunctionBuilder method doToFunction.
@Override
protected ScoreFunction doToFunction(QueryShardContext context) {
MappedFieldType fieldType = context.getMapperService().fullName(field);
IndexNumericFieldData fieldData = null;
if (fieldType == null) {
if (missing == null) {
throw new ElasticsearchException("Unable to find a field mapper for field [" + field + "]. No 'missing' value defined.");
}
} else {
fieldData = context.getForField(fieldType);
}
return new FieldValueFactorFunction(field, factor, modifier, missing, fieldData);
}
Aggregations