Search in sources :

Example 1 with FieldValueFactorFunction

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);
}
Also used : TermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) SortedNumericDVIndexFieldData(org.elasticsearch.index.fielddata.plain.SortedNumericDVIndexFieldData) FunctionScoreQuery(org.elasticsearch.common.lucene.search.function.FunctionScoreQuery) FieldValueFactorFunction(org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) Index(org.elasticsearch.index.Index) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery)

Example 2 with FieldValueFactorFunction

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);
}
Also used : FieldValueFactorFunction(org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) IndexNumericFieldData(org.elasticsearch.index.fielddata.IndexNumericFieldData) ElasticsearchException(org.elasticsearch.ElasticsearchException)

Aggregations

FieldValueFactorFunction (org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction)2 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)2 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 FunctionScoreQuery (org.elasticsearch.common.lucene.search.function.FunctionScoreQuery)1 Index (org.elasticsearch.index.Index)1 IndexNumericFieldData (org.elasticsearch.index.fielddata.IndexNumericFieldData)1 SortedNumericDVIndexFieldData (org.elasticsearch.index.fielddata.plain.SortedNumericDVIndexFieldData)1 TermsAggregationBuilder (org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder)1