Search in sources :

Example 11 with DocValueFormat

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

the class SearchAfterBuilder method buildFieldDoc.

public static FieldDoc buildFieldDoc(SortAndFormats sort, Object[] values) {
    if (sort == null || sort.sort.getSort() == null || sort.sort.getSort().length == 0) {
        throw new IllegalArgumentException("Sort must contain at least one field.");
    }
    SortField[] sortFields = sort.sort.getSort();
    if (sortFields.length != values.length) {
        throw new IllegalArgumentException(SEARCH_AFTER.getPreferredName() + " has " + values.length + " value(s) but sort has " + sort.sort.getSort().length + ".");
    }
    Object[] fieldValues = new Object[sortFields.length];
    for (int i = 0; i < sortFields.length; i++) {
        SortField sortField = sortFields[i];
        DocValueFormat format = sort.formats[i];
        if (values[i] != null) {
            fieldValues[i] = convertValueFromSortField(values[i], sortField, format);
        } else {
            fieldValues[i] = null;
        }
    }
    /*
         * We set the doc id to Integer.MAX_VALUE in order to make sure that the search starts "after" the first document that is equal to
         * the field values.
         */
    return new FieldDoc(Integer.MAX_VALUE, 0, fieldValues);
}
Also used : FieldDoc(org.apache.lucene.search.FieldDoc) DocValueFormat(org.elasticsearch.search.DocValueFormat) SortField(org.apache.lucene.search.SortField)

Example 12 with DocValueFormat

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

the class InternalHDRPercentilesRanksTests method createTestInstance.

@Override
protected InternalHDRPercentileRanks createTestInstance(String name, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) {
    double[] cdfValues = new double[] { 0.5 };
    int numberOfSignificantValueDigits = 3;
    DoubleHistogram state = new DoubleHistogram(numberOfSignificantValueDigits);
    int numValues = randomInt(100);
    for (int i = 0; i < numValues; ++i) {
        state.recordValue(randomDouble());
    }
    boolean keyed = false;
    DocValueFormat format = DocValueFormat.RAW;
    return new InternalHDRPercentileRanks(name, cdfValues, state, keyed, format, pipelineAggregators, metaData);
}
Also used : DoubleHistogram(org.HdrHistogram.DoubleHistogram) DocValueFormat(org.elasticsearch.search.DocValueFormat) InternalHDRPercentileRanks(org.elasticsearch.search.aggregations.metrics.percentiles.hdr.InternalHDRPercentileRanks)

Example 13 with DocValueFormat

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

the class InternalTDigestPercentilesRanksTests method createTestInstance.

@Override
protected InternalTDigestPercentileRanks createTestInstance(String name, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) {
    double[] cdfValues = new double[] { 0.5 };
    TDigestState state = new TDigestState(100);
    int numValues = randomInt(100);
    for (int i = 0; i < numValues; ++i) {
        state.add(randomDouble());
    }
    boolean keyed = false;
    DocValueFormat format = DocValueFormat.RAW;
    return new InternalTDigestPercentileRanks(name, cdfValues, state, keyed, format, pipelineAggregators, metaData);
}
Also used : DocValueFormat(org.elasticsearch.search.DocValueFormat)

Example 14 with DocValueFormat

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

the class DfsQueryPhaseTests method testDfsWith2Shards.

public void testDfsWith2Shards() throws IOException {
    AtomicArray<DfsSearchResult> results = new AtomicArray<>(2);
    AtomicReference<AtomicArray<QuerySearchResultProvider>> responseRef = new AtomicReference<>();
    results.set(0, new DfsSearchResult(1, new SearchShardTarget("node1", new Index("test", "na"), 0)));
    results.set(1, new DfsSearchResult(2, new SearchShardTarget("node2", new Index("test", "na"), 0)));
    results.get(0).termsStatistics(new Term[0], new TermStatistics[0]);
    results.get(1).termsStatistics(new Term[0], new TermStatistics[0]);
    SearchPhaseController controller = new SearchPhaseController(Settings.EMPTY, BigArrays.NON_RECYCLING_INSTANCE, null);
    SearchTransportService searchTransportService = new SearchTransportService(Settings.builder().put("search.remote.connect", false).build(), null, null) {

        @Override
        public void sendExecuteQuery(Transport.Connection connection, QuerySearchRequest request, SearchTask task, ActionListener<QuerySearchResult> listener) {
            if (request.id() == 1) {
                QuerySearchResult queryResult = new QuerySearchResult(123, new SearchShardTarget("node1", new Index("test", "na"), 0));
                queryResult.topDocs(new TopDocs(1, new ScoreDoc[] { new ScoreDoc(42, 1.0F) }, 2.0F), new DocValueFormat[0]);
                // the size of the result set
                queryResult.size(2);
                listener.onResponse(queryResult);
            } else if (request.id() == 2) {
                QuerySearchResult queryResult = new QuerySearchResult(123, new SearchShardTarget("node2", new Index("test", "na"), 0));
                queryResult.topDocs(new TopDocs(1, new ScoreDoc[] { new ScoreDoc(84, 2.0F) }, 2.0F), new DocValueFormat[0]);
                // the size of the result set
                queryResult.size(2);
                listener.onResponse(queryResult);
            } else {
                fail("no such request ID: " + request.id());
            }
        }
    };
    MockSearchPhaseContext mockSearchPhaseContext = new MockSearchPhaseContext(2);
    mockSearchPhaseContext.searchTransport = searchTransportService;
    DfsQueryPhase phase = new DfsQueryPhase(results, controller, (response) -> new SearchPhase("test") {

        @Override
        public void run() throws IOException {
            responseRef.set(response.results);
        }
    }, mockSearchPhaseContext);
    assertEquals("dfs_query", phase.getName());
    phase.run();
    mockSearchPhaseContext.assertNoFailure();
    assertNotNull(responseRef.get());
    assertNotNull(responseRef.get().get(0));
    assertNull(responseRef.get().get(0).fetchResult());
    assertEquals(1, responseRef.get().get(0).queryResult().topDocs().totalHits);
    assertEquals(42, responseRef.get().get(0).queryResult().topDocs().scoreDocs[0].doc);
    assertNotNull(responseRef.get().get(1));
    assertNull(responseRef.get().get(1).fetchResult());
    assertEquals(1, responseRef.get().get(1).queryResult().topDocs().totalHits);
    assertEquals(84, responseRef.get().get(1).queryResult().topDocs().scoreDocs[0].doc);
    assertTrue(mockSearchPhaseContext.releasedSearchContexts.isEmpty());
    assertEquals(2, mockSearchPhaseContext.numSuccess.get());
}
Also used : AtomicArray(org.elasticsearch.common.util.concurrent.AtomicArray) DfsSearchResult(org.elasticsearch.search.dfs.DfsSearchResult) DocValueFormat(org.elasticsearch.search.DocValueFormat) AtomicReference(java.util.concurrent.atomic.AtomicReference) Index(org.elasticsearch.index.Index) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ScoreDoc(org.apache.lucene.search.ScoreDoc) TopDocs(org.apache.lucene.search.TopDocs) ActionListener(org.elasticsearch.action.ActionListener) QuerySearchResult(org.elasticsearch.search.query.QuerySearchResult) SearchShardTarget(org.elasticsearch.search.SearchShardTarget) QuerySearchRequest(org.elasticsearch.search.query.QuerySearchRequest)

Example 15 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)

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