Search in sources :

Example 21 with AliasFilter

use of org.elasticsearch.search.internal.AliasFilter in project elasticsearch by elastic.

the class ExplainRequestTests method testSerialize.

public void testSerialize() throws IOException {
    try (BytesStreamOutput output = new BytesStreamOutput()) {
        ExplainRequest request = new ExplainRequest("index", "type", "id");
        request.fetchSourceContext(new FetchSourceContext(true, new String[] { "field1.*" }, new String[] { "field2.*" }));
        request.filteringAlias(new AliasFilter(QueryBuilders.termQuery("filter_field", "value"), new String[] { "alias0", "alias1" }));
        request.preference("the_preference");
        request.query(QueryBuilders.termQuery("field", "value"));
        request.storedFields(new String[] { "field1", "field2" });
        request.routing("some_routing");
        request.writeTo(output);
        try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
            ExplainRequest readRequest = new ExplainRequest();
            readRequest.readFrom(in);
            assertEquals(request.filteringAlias(), readRequest.filteringAlias());
            assertArrayEquals(request.storedFields(), readRequest.storedFields());
            assertEquals(request.preference(), readRequest.preference());
            assertEquals(request.query(), readRequest.query());
            assertEquals(request.routing(), readRequest.routing());
            assertEquals(request.fetchSourceContext(), readRequest.fetchSourceContext());
        }
    }
}
Also used : AliasFilter(org.elasticsearch.search.internal.AliasFilter) FetchSourceContext(org.elasticsearch.search.fetch.subphase.FetchSourceContext) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.elasticsearch.common.io.stream.StreamInput) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) ExplainRequest(org.elasticsearch.action.explain.ExplainRequest) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Example 22 with AliasFilter

use of org.elasticsearch.search.internal.AliasFilter in project elasticsearch by elastic.

the class SearchServiceTests method testTimeout.

public void testTimeout() throws IOException {
    createIndex("index");
    final SearchService service = getInstanceFromNode(SearchService.class);
    final IndicesService indicesService = getInstanceFromNode(IndicesService.class);
    final IndexService indexService = indicesService.indexServiceSafe(resolveIndex("index"));
    final IndexShard indexShard = indexService.getShard(0);
    final SearchContext contextWithDefaultTimeout = service.createContext(new ShardSearchLocalRequest(indexShard.shardId(), 1, SearchType.DEFAULT, new SearchSourceBuilder(), new String[0], false, new AliasFilter(null, Strings.EMPTY_ARRAY), 1.0f), null);
    // the search context should inherit the default timeout
    assertThat(contextWithDefaultTimeout.timeout(), equalTo(TimeValue.timeValueSeconds(5)));
    final long seconds = randomIntBetween(6, 10);
    final SearchContext context = service.createContext(new ShardSearchLocalRequest(indexShard.shardId(), 1, SearchType.DEFAULT, new SearchSourceBuilder().timeout(TimeValue.timeValueSeconds(seconds)), new String[0], false, new AliasFilter(null, Strings.EMPTY_ARRAY), 1.0f), null);
    // the search context should inherit the query timeout
    assertThat(context.timeout(), equalTo(TimeValue.timeValueSeconds(seconds)));
}
Also used : AliasFilter(org.elasticsearch.search.internal.AliasFilter) ShardSearchLocalRequest(org.elasticsearch.search.internal.ShardSearchLocalRequest) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) IndicesService(org.elasticsearch.indices.IndicesService) SearchContext(org.elasticsearch.search.internal.SearchContext) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder)

Aggregations

AliasFilter (org.elasticsearch.search.internal.AliasFilter)22 HashMap (java.util.HashMap)11 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)10 ShardId (org.elasticsearch.index.shard.ShardId)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 ShardIterator (org.elasticsearch.cluster.routing.ShardIterator)6 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)6 NamedWriteableAwareStreamInput (org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput)6 StreamInput (org.elasticsearch.common.io.stream.StreamInput)6 Set (java.util.Set)5 IOException (java.io.IOException)4 List (java.util.List)4 ActionListener (org.elasticsearch.action.ActionListener)4 GroupShardsIterator (org.elasticsearch.cluster.routing.GroupShardsIterator)4 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)4 Index (org.elasticsearch.index.Index)4 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3 CountDownLatch (java.util.concurrent.CountDownLatch)3