Search in sources :

Example 46 with BytesArray

use of org.elasticsearch.common.bytes.BytesArray in project elasticsearch by elastic.

the class ReindexFromRemoteBuildRestClientTests method testBuildRestClient.

public void testBuildRestClient() throws Exception {
    RemoteInfo remoteInfo = new RemoteInfo("https", "localhost", 9200, new BytesArray("ignored"), null, null, emptyMap(), RemoteInfo.DEFAULT_SOCKET_TIMEOUT, RemoteInfo.DEFAULT_CONNECT_TIMEOUT);
    long taskId = randomLong();
    List<Thread> threads = synchronizedList(new ArrayList<>());
    RestClient client = TransportReindexAction.buildRestClient(remoteInfo, taskId, threads);
    try {
        assertBusy(() -> assertThat(threads, hasSize(2)));
        int i = 0;
        for (Thread thread : threads) {
            assertEquals("es-client-" + taskId + "-" + i, thread.getName());
            i++;
        }
    } finally {
        client.close();
    }
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) RestClient(org.elasticsearch.client.RestClient) RemoteInfo(org.elasticsearch.index.reindex.remote.RemoteInfo)

Example 47 with BytesArray

use of org.elasticsearch.common.bytes.BytesArray in project elasticsearch by elastic.

the class ReindexFromRemoteWhitelistTests method testWhitelistedByPrefix.

public void testWhitelistedByPrefix() {
    checkRemoteWhitelist(buildRemoteWhitelist(singletonList("*.example.com:9200")), new RemoteInfo(randomAsciiOfLength(5), "es.example.com", 9200, new BytesArray("test"), null, null, emptyMap(), RemoteInfo.DEFAULT_SOCKET_TIMEOUT, RemoteInfo.DEFAULT_CONNECT_TIMEOUT));
    checkRemoteWhitelist(buildRemoteWhitelist(singletonList("*.example.com:9200")), newRemoteInfo("6e134134a1.us-east-1.aws.example.com", 9200));
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) RemoteInfo(org.elasticsearch.index.reindex.remote.RemoteInfo)

Example 48 with BytesArray

use of org.elasticsearch.common.bytes.BytesArray in project elasticsearch by elastic.

the class CancelTests method testUpdateByQueryCancelWithWorkers.

public void testUpdateByQueryCancelWithWorkers() throws Exception {
    BytesReference pipeline = new BytesArray("{\n" + "  \"description\" : \"sets processed to true\",\n" + "  \"processors\" : [ {\n" + "      \"test\" : {}\n" + "  } ]\n" + "}");
    assertAcked(client().admin().cluster().preparePutPipeline("set-processed", pipeline, XContentType.JSON).get());
    testCancel(UpdateByQueryAction.NAME, updateByQuery().setPipeline("set-processed").source(INDEX).setSlices(5), (response, total, modified) -> {
        assertThat(response, matcher().updated(modified).reasonCancelled(equalTo("by user request")).slices(hasSize(5)));
        assertHitCount(client().prepareSearch(INDEX).setSize(0).setQuery(termQuery("processed", true)).get(), modified);
    }, equalTo("update-by-query [" + INDEX + "]"));
    assertAcked(client().admin().cluster().deletePipeline(new DeletePipelineRequest("set-processed")).get());
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) DeletePipelineRequest(org.elasticsearch.action.ingest.DeletePipelineRequest) BytesArray(org.elasticsearch.common.bytes.BytesArray)

Example 49 with BytesArray

use of org.elasticsearch.common.bytes.BytesArray in project elasticsearch by elastic.

the class RemoteRequestBuildersTests method testInitialSearchEntity.

public void testInitialSearchEntity() throws IOException {
    SearchRequest searchRequest = new SearchRequest();
    searchRequest.source(new SearchSourceBuilder());
    String query = "{\"match_all\":{}}";
    HttpEntity entity = initialSearchEntity(searchRequest, new BytesArray(query));
    assertEquals(ContentType.APPLICATION_JSON.toString(), entity.getContentType().getValue());
    assertEquals("{\"query\":" + query + ",\"_source\":true}", Streams.copyToString(new InputStreamReader(entity.getContent(), StandardCharsets.UTF_8)));
    // Source filtering is included if set up
    searchRequest.source().fetchSource(new String[] { "in1", "in2" }, new String[] { "out" });
    entity = initialSearchEntity(searchRequest, new BytesArray(query));
    assertEquals(ContentType.APPLICATION_JSON.toString(), entity.getContentType().getValue());
    assertEquals("{\"query\":" + query + ",\"_source\":{\"includes\":[\"in1\",\"in2\"],\"excludes\":[\"out\"]}}", Streams.copyToString(new InputStreamReader(entity.getContent(), StandardCharsets.UTF_8)));
    // Invalid XContent fails
    RuntimeException e = expectThrows(RuntimeException.class, () -> initialSearchEntity(searchRequest, new BytesArray("{}, \"trailing\": {}")));
    assertThat(e.getCause().getMessage(), containsString("Unexpected character (',' (code 44))"));
    e = expectThrows(RuntimeException.class, () -> initialSearchEntity(searchRequest, new BytesArray("{")));
    assertThat(e.getCause().getMessage(), containsString("Unexpected end-of-input"));
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) BytesArray(org.elasticsearch.common.bytes.BytesArray) HttpEntity(org.apache.http.HttpEntity) InputStreamReader(java.io.InputStreamReader) Matchers.containsString(org.hamcrest.Matchers.containsString) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder)

Example 50 with BytesArray

use of org.elasticsearch.common.bytes.BytesArray in project elasticsearch by elastic.

the class ReindexRequestTests method testReindexFromRemoteDoesNotSupportWorkers.

public void testReindexFromRemoteDoesNotSupportWorkers() {
    ReindexRequest reindex = newRequest();
    reindex.setRemoteInfo(new RemoteInfo(randomAsciiOfLength(5), randomAsciiOfLength(5), between(1, Integer.MAX_VALUE), new BytesArray("real_query"), null, null, emptyMap(), RemoteInfo.DEFAULT_SOCKET_TIMEOUT, RemoteInfo.DEFAULT_CONNECT_TIMEOUT));
    reindex.setSlices(between(2, Integer.MAX_VALUE));
    ActionRequestValidationException e = reindex.validate();
    assertEquals("Validation Failed: 1: reindex from remote sources doesn't support workers > 1 but was [" + reindex.getSlices() + "];", e.getMessage());
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) ActionRequestValidationException(org.elasticsearch.action.ActionRequestValidationException) RemoteInfo(org.elasticsearch.index.reindex.remote.RemoteInfo)

Aggregations

BytesArray (org.elasticsearch.common.bytes.BytesArray)203 BytesReference (org.elasticsearch.common.bytes.BytesReference)36 Matchers.containsString (org.hamcrest.Matchers.containsString)31 IOException (java.io.IOException)29 StreamInput (org.elasticsearch.common.io.stream.StreamInput)24 ParsedDocument (org.elasticsearch.index.mapper.ParsedDocument)24 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)21 HashMap (java.util.HashMap)17 BytesRef (org.apache.lucene.util.BytesRef)17 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)14 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)14 FakeRestRequest (org.elasticsearch.test.rest.FakeRestRequest)13 ArrayList (java.util.ArrayList)12 TopDocs (org.apache.lucene.search.TopDocs)12 SearchResponse (org.elasticsearch.action.search.SearchResponse)12 Document (org.elasticsearch.index.mapper.ParseContext.Document)12 Index (org.elasticsearch.index.Index)11 Map (java.util.Map)10 IndexableField (org.apache.lucene.index.IndexableField)10 IndexService (org.elasticsearch.index.IndexService)10