Search in sources :

Example 91 with MappedFieldType

use of org.elasticsearch.index.mapper.MappedFieldType in project elasticsearch by elastic.

the class UidFieldTypeTests method testRangeQuery.

public void testRangeQuery() {
    MappedFieldType ft = createDefaultFieldType();
    ft.setName("_uid");
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> ft.rangeQuery(null, null, randomBoolean(), randomBoolean(), null));
    assertEquals("Field [_uid] of type [_uid] does not support range queries", e.getMessage());
}
Also used : MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType)

Example 92 with MappedFieldType

use of org.elasticsearch.index.mapper.MappedFieldType in project elasticsearch by elastic.

the class FieldMaskingSpanQueryBuilderTests method doAssertLuceneQuery.

@Override
protected void doAssertLuceneQuery(FieldMaskingSpanQueryBuilder queryBuilder, Query query, SearchContext context) throws IOException {
    String fieldInQuery = queryBuilder.fieldName();
    MappedFieldType fieldType = context.getQueryShardContext().fieldMapper(fieldInQuery);
    if (fieldType != null) {
        fieldInQuery = fieldType.name();
    }
    assertThat(query, instanceOf(FieldMaskingSpanQuery.class));
    FieldMaskingSpanQuery fieldMaskingSpanQuery = (FieldMaskingSpanQuery) query;
    assertThat(fieldMaskingSpanQuery.getField(), equalTo(fieldInQuery));
    assertThat(fieldMaskingSpanQuery.getMaskedQuery(), equalTo(queryBuilder.innerQuery().toQuery(context.getQueryShardContext())));
}
Also used : MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) FieldMaskingSpanQuery(org.apache.lucene.search.spans.FieldMaskingSpanQuery)

Example 93 with MappedFieldType

use of org.elasticsearch.index.mapper.MappedFieldType in project elasticsearch by elastic.

the class ExtendedStatsAggregatorTests method testEmpty.

public void testEmpty() throws IOException {
    MappedFieldType ft = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.LONG);
    ft.setName("field");
    testCase(ft, iw -> {
    }, stats -> {
        assertEquals(0d, stats.getCount(), 0);
        assertEquals(0d, stats.getSum(), 0);
        assertEquals(Float.NaN, stats.getAvg(), 0);
        assertEquals(Double.POSITIVE_INFINITY, stats.getMin(), 0);
        assertEquals(Double.NEGATIVE_INFINITY, stats.getMax(), 0);
        assertEquals(Double.NaN, stats.getVariance(), 0);
        assertEquals(Double.NaN, stats.getStdDeviation(), 0);
        assertEquals(0d, stats.getSumOfSquares(), 0);
    });
}
Also used : MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType)

Example 94 with MappedFieldType

use of org.elasticsearch.index.mapper.MappedFieldType in project elasticsearch by elastic.

the class ExtendedStatsAggregatorTests method testRandomDoubles.

public void testRandomDoubles() throws IOException {
    MappedFieldType ft = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.DOUBLE);
    ft.setName("field");
    final ExtendedSimpleStatsAggregator expected = new ExtendedSimpleStatsAggregator();
    testCase(ft, iw -> {
        int numDocs = randomIntBetween(10, 50);
        for (int i = 0; i < numDocs; i++) {
            Document doc = new Document();
            int numValues = randomIntBetween(1, 5);
            for (int j = 0; j < numValues; j++) {
                double value = randomDoubleBetween(-100d, 100d, true);
                long valueAsLong = NumericUtils.doubleToSortableLong(value);
                doc.add(new SortedNumericDocValuesField("field", valueAsLong));
                expected.add(value);
            }
            iw.addDocument(doc);
        }
    }, stats -> {
        assertEquals(expected.count, stats.getCount(), 0);
        assertEquals(expected.sum, stats.getSum(), TOLERANCE);
        assertEquals(expected.min, stats.getMin(), 0);
        assertEquals(expected.max, stats.getMax(), 0);
        assertEquals(expected.sum / expected.count, stats.getAvg(), TOLERANCE);
        assertEquals(expected.sumOfSqrs, stats.getSumOfSquares(), TOLERANCE);
        assertEquals(expected.stdDev(), stats.getStdDeviation(), TOLERANCE);
        assertEquals(expected.variance(), stats.getVariance(), TOLERANCE);
        assertEquals(expected.stdDevBound(ExtendedStats.Bounds.LOWER, stats.getSigma()), stats.getStdDeviationBound(ExtendedStats.Bounds.LOWER), TOLERANCE);
        assertEquals(expected.stdDevBound(ExtendedStats.Bounds.UPPER, stats.getSigma()), stats.getStdDeviationBound(ExtendedStats.Bounds.UPPER), TOLERANCE);
    });
}
Also used : SortedNumericDocValuesField(org.apache.lucene.document.SortedNumericDocValuesField) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) Document(org.apache.lucene.document.Document)

Example 95 with MappedFieldType

use of org.elasticsearch.index.mapper.MappedFieldType in project elasticsearch by elastic.

the class ExtendedStatsAggregatorTests method testRandomLongs.

public void testRandomLongs() throws IOException {
    MappedFieldType ft = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.LONG);
    ft.setName("field");
    final ExtendedSimpleStatsAggregator expected = new ExtendedSimpleStatsAggregator();
    testCase(ft, iw -> {
        int numDocs = randomIntBetween(10, 50);
        for (int i = 0; i < numDocs; i++) {
            Document doc = new Document();
            int numValues = randomIntBetween(1, 5);
            for (int j = 0; j < numValues; j++) {
                long value = randomIntBetween(-100, 100);
                doc.add(new SortedNumericDocValuesField("field", value));
                expected.add(value);
            }
            iw.addDocument(doc);
        }
    }, stats -> {
        assertEquals(expected.count, stats.getCount(), 0);
        assertEquals(expected.sum, stats.getSum(), TOLERANCE);
        assertEquals(expected.min, stats.getMin(), 0);
        assertEquals(expected.max, stats.getMax(), 0);
        assertEquals(expected.sum / expected.count, stats.getAvg(), TOLERANCE);
        assertEquals(expected.sumOfSqrs, stats.getSumOfSquares(), TOLERANCE);
        assertEquals(expected.stdDev(), stats.getStdDeviation(), TOLERANCE);
        assertEquals(expected.variance(), stats.getVariance(), TOLERANCE);
        assertEquals(expected.stdDevBound(ExtendedStats.Bounds.LOWER, stats.getSigma()), stats.getStdDeviationBound(ExtendedStats.Bounds.LOWER), TOLERANCE);
        assertEquals(expected.stdDevBound(ExtendedStats.Bounds.UPPER, stats.getSigma()), stats.getStdDeviationBound(ExtendedStats.Bounds.UPPER), TOLERANCE);
    });
}
Also used : SortedNumericDocValuesField(org.apache.lucene.document.SortedNumericDocValuesField) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) Document(org.apache.lucene.document.Document)

Aggregations

MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)122 IndexSearcher (org.apache.lucene.search.IndexSearcher)34 IndexReader (org.apache.lucene.index.IndexReader)33 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)29 Directory (org.apache.lucene.store.Directory)29 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)26 Document (org.apache.lucene.document.Document)23 Query (org.apache.lucene.search.Query)19 SortedNumericDocValuesField (org.apache.lucene.document.SortedNumericDocValuesField)17 Term (org.apache.lucene.index.Term)17 DocumentMapper (org.elasticsearch.index.mapper.DocumentMapper)12 ParsedDocument (org.elasticsearch.index.mapper.ParsedDocument)11 IndexableField (org.apache.lucene.index.IndexableField)9 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)9 ArrayList (java.util.ArrayList)8 MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)8 TermQuery (org.apache.lucene.search.TermQuery)8 IndexNumericFieldData (org.elasticsearch.index.fielddata.IndexNumericFieldData)8 FieldMapper (org.elasticsearch.index.mapper.FieldMapper)8 Analyzer (org.apache.lucene.analysis.Analyzer)7