Search in sources :

Example 16 with DocValueFormat

use of org.elasticsearch.search.DocValueFormat in project elasticsearch by elastic.

the class InternalBinaryRangeTests method createTestInstance.

@Override
protected InternalBinaryRange createTestInstance(String name, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) {
    boolean keyed = randomBoolean();
    DocValueFormat format = DocValueFormat.RAW;
    List<InternalBinaryRange.Bucket> buckets = new ArrayList<>();
    for (int i = 0; i < RANGES.length; ++i) {
        final int docCount = randomIntBetween(1, 100);
        buckets.add(new InternalBinaryRange.Bucket(format, keyed, randomAsciiOfLength(10), RANGES[i].v1(), RANGES[i].v2(), docCount, InternalAggregations.EMPTY));
    }
    return new InternalBinaryRange(name, format, keyed, buckets, pipelineAggregators, Collections.emptyMap());
}
Also used : DocValueFormat(org.elasticsearch.search.DocValueFormat) ArrayList(java.util.ArrayList)

Example 17 with DocValueFormat

use of org.elasticsearch.search.DocValueFormat in project elasticsearch by elastic.

the class SignificantLongTermsTests method createTestInstance.

@Override
protected InternalSignificantTerms createTestInstance(String name, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) {
    DocValueFormat format = DocValueFormat.RAW;
    int requiredSize = randomIntBetween(1, 5);
    int shardSize = requiredSize + 2;
    final int numBuckets = randomInt(shardSize);
    long globalSubsetSize = 0;
    long globalSupersetSize = 0;
    List<SignificantLongTerms.Bucket> buckets = new ArrayList<>(numBuckets);
    Set<Long> terms = new HashSet<>();
    for (int i = 0; i < numBuckets; ++i) {
        long term = randomValueOtherThanMany(l -> terms.add(l) == false, random()::nextLong);
        int subsetDf = randomIntBetween(1, 10);
        int supersetDf = randomIntBetween(subsetDf, 20);
        int supersetSize = randomIntBetween(supersetDf, 30);
        globalSubsetSize += subsetDf;
        globalSupersetSize += supersetSize;
        buckets.add(new SignificantLongTerms.Bucket(subsetDf, subsetDf, supersetDf, supersetSize, term, EMPTY, format));
    }
    return new SignificantLongTerms(name, requiredSize, 1L, pipelineAggregators, metaData, format, globalSubsetSize, globalSupersetSize, significanceHeuristic, buckets);
}
Also used : DocValueFormat(org.elasticsearch.search.DocValueFormat) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 18 with DocValueFormat

use of org.elasticsearch.search.DocValueFormat in project elasticsearch by elastic.

the class ExtendedBoundsTests method testParseAndValidate.

public void testParseAndValidate() {
    long now = randomLong();
    Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1).build();
    SearchContext context = mock(SearchContext.class);
    QueryShardContext qsc = new QueryShardContext(0, new IndexSettings(IndexMetaData.builder("foo").settings(indexSettings).build(), indexSettings), null, null, null, null, null, xContentRegistry(), null, null, () -> now);
    when(context.getQueryShardContext()).thenReturn(qsc);
    FormatDateTimeFormatter formatter = Joda.forPattern("dateOptionalTime");
    DocValueFormat format = new DocValueFormat.DateTime(formatter, DateTimeZone.UTC);
    ExtendedBounds expected = randomParsedExtendedBounds();
    ExtendedBounds parsed = unparsed(expected).parseAndValidate("test", context, format);
    // parsed won't *equal* expected because equal includes the String parts
    assertEquals(expected.getMin(), parsed.getMin());
    assertEquals(expected.getMax(), parsed.getMax());
    parsed = new ExtendedBounds("now", null).parseAndValidate("test", context, format);
    assertEquals(now, (long) parsed.getMin());
    assertNull(parsed.getMax());
    parsed = new ExtendedBounds(null, "now").parseAndValidate("test", context, format);
    assertNull(parsed.getMin());
    assertEquals(now, (long) parsed.getMax());
    SearchParseException e = expectThrows(SearchParseException.class, () -> new ExtendedBounds(100L, 90L).parseAndValidate("test", context, format));
    assertEquals("[extended_bounds.min][100] cannot be greater than [extended_bounds.max][90] for histogram aggregation [test]", e.getMessage());
    e = expectThrows(SearchParseException.class, () -> unparsed(new ExtendedBounds(100L, 90L)).parseAndValidate("test", context, format));
    assertEquals("[extended_bounds.min][100] cannot be greater than [extended_bounds.max][90] for histogram aggregation [test]", e.getMessage());
}
Also used : SearchParseException(org.elasticsearch.search.SearchParseException) FormatDateTimeFormatter(org.elasticsearch.common.joda.FormatDateTimeFormatter) DocValueFormat(org.elasticsearch.search.DocValueFormat) IndexSettings(org.elasticsearch.index.IndexSettings) SearchContext(org.elasticsearch.search.internal.SearchContext) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Aggregations

DocValueFormat (org.elasticsearch.search.DocValueFormat)18 ArrayList (java.util.ArrayList)10 HashSet (java.util.HashSet)5 FieldDoc (org.apache.lucene.search.FieldDoc)2 ScoreDoc (org.apache.lucene.search.ScoreDoc)2 Sort (org.apache.lucene.search.Sort)2 SortField (org.apache.lucene.search.SortField)2 TopDocs (org.apache.lucene.search.TopDocs)2 BytesRef (org.apache.lucene.util.BytesRef)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 AbstractList (java.util.AbstractList)1 Callable (java.util.concurrent.Callable)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 DoubleHistogram (org.HdrHistogram.DoubleHistogram)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 Term (org.apache.lucene.index.Term)1 MinDocQuery (org.apache.lucene.queries.MinDocQuery)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 Collector (org.apache.lucene.search.Collector)1