Search in sources :

Example 26 with BytesArray

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

the class PercolatorQuerySearchIT method testTakePositionOffsetGapIntoAccount.

public void testTakePositionOffsetGapIntoAccount() throws Exception {
    createIndex("test", client().admin().indices().prepareCreate("test").addMapping("type", "field", "type=text,position_increment_gap=5").addMapping("queries", "query", "type=percolator"));
    client().prepareIndex("test", "queries", "1").setSource(jsonBuilder().startObject().field("query", new MatchPhraseQueryBuilder("field", "brown fox").slop(4)).endObject()).get();
    client().prepareIndex("test", "queries", "2").setSource(jsonBuilder().startObject().field("query", new MatchPhraseQueryBuilder("field", "brown fox").slop(5)).endObject()).get();
    client().admin().indices().prepareRefresh().get();
    SearchResponse response = client().prepareSearch().setQuery(new PercolateQueryBuilder("query", "type", new BytesArray("{\"field\" : [\"brown\", \"fox\"]}"), XContentType.JSON)).get();
    assertHitCount(response, 1);
    assertThat(response.getHits().getAt(0).getId(), equalTo("2"));
}
Also used : MatchPhraseQueryBuilder(org.elasticsearch.index.query.MatchPhraseQueryBuilder) BytesArray(org.elasticsearch.common.bytes.BytesArray) SearchResponse(org.elasticsearch.action.search.SearchResponse) MultiSearchResponse(org.elasticsearch.action.search.MultiSearchResponse)

Example 27 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 28 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 29 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 30 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)

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