Search in sources :

Example 1 with SortedNumericDVIndexFieldData

use of org.elasticsearch.index.fielddata.plain.SortedNumericDVIndexFieldData 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 SortedNumericDVIndexFieldData

use of org.elasticsearch.index.fielddata.plain.SortedNumericDVIndexFieldData in project elasticsearch by elastic.

the class IndexFieldDataServiceTests method testGetForFieldDefaults.

public void testGetForFieldDefaults() {
    final IndexService indexService = createIndex("test");
    final IndexFieldDataService ifdService = indexService.fieldData();
    final BuilderContext ctx = new BuilderContext(indexService.getIndexSettings().getSettings(), new ContentPath(1));
    final MappedFieldType stringMapper = new KeywordFieldMapper.Builder("string").build(ctx).fieldType();
    ifdService.clear();
    IndexFieldData<?> fd = ifdService.getForField(stringMapper);
    assertTrue(fd instanceof SortedSetDVOrdinalsIndexFieldData);
    for (MappedFieldType mapper : Arrays.asList(new NumberFieldMapper.Builder("int", NumberFieldMapper.NumberType.BYTE).build(ctx).fieldType(), new NumberFieldMapper.Builder("int", NumberFieldMapper.NumberType.SHORT).build(ctx).fieldType(), new NumberFieldMapper.Builder("int", NumberFieldMapper.NumberType.INTEGER).build(ctx).fieldType(), new NumberFieldMapper.Builder("long", NumberFieldMapper.NumberType.LONG).build(ctx).fieldType())) {
        ifdService.clear();
        fd = ifdService.getForField(mapper);
        assertTrue(fd instanceof SortedNumericDVIndexFieldData);
    }
    final MappedFieldType floatMapper = new NumberFieldMapper.Builder("float", NumberFieldMapper.NumberType.FLOAT).build(ctx).fieldType();
    ifdService.clear();
    fd = ifdService.getForField(floatMapper);
    assertTrue(fd instanceof SortedNumericDVIndexFieldData);
    final MappedFieldType doubleMapper = new NumberFieldMapper.Builder("double", NumberFieldMapper.NumberType.DOUBLE).build(ctx).fieldType();
    ifdService.clear();
    fd = ifdService.getForField(doubleMapper);
    assertTrue(fd instanceof SortedNumericDVIndexFieldData);
}
Also used : SortedSetDVOrdinalsIndexFieldData(org.elasticsearch.index.fielddata.plain.SortedSetDVOrdinalsIndexFieldData) NumberFieldMapper(org.elasticsearch.index.mapper.NumberFieldMapper) IndexService(org.elasticsearch.index.IndexService) SortedNumericDVIndexFieldData(org.elasticsearch.index.fielddata.plain.SortedNumericDVIndexFieldData) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) BuilderContext(org.elasticsearch.index.mapper.Mapper.BuilderContext) ContentPath(org.elasticsearch.index.mapper.ContentPath)

Aggregations

SortedNumericDVIndexFieldData (org.elasticsearch.index.fielddata.plain.SortedNumericDVIndexFieldData)2 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)2 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1 FieldValueFactorFunction (org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction)1 FunctionScoreQuery (org.elasticsearch.common.lucene.search.function.FunctionScoreQuery)1 Index (org.elasticsearch.index.Index)1 IndexService (org.elasticsearch.index.IndexService)1 SortedSetDVOrdinalsIndexFieldData (org.elasticsearch.index.fielddata.plain.SortedSetDVOrdinalsIndexFieldData)1 ContentPath (org.elasticsearch.index.mapper.ContentPath)1 BuilderContext (org.elasticsearch.index.mapper.Mapper.BuilderContext)1 NumberFieldMapper (org.elasticsearch.index.mapper.NumberFieldMapper)1 TermsAggregationBuilder (org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder)1