Search in sources :

Example 6 with BytesArray

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

the class BlobRecoveryHandler method getExistingDigestsFromTarget.

private Set<BytesArray> getExistingDigestsFromTarget(byte prefix) {
    BlobStartPrefixResponse response = (BlobStartPrefixResponse) transportService.submitRequest(request.targetNode(), BlobRecoveryTarget.Actions.START_PREFIX, new BlobStartPrefixSyncRequest(request.recoveryId(), request.shardId(), prefix), TransportRequestOptions.EMPTY, new FutureTransportResponseHandler<TransportResponse>() {

        @Override
        public TransportResponse newInstance() {
            return new BlobStartPrefixResponse();
        }
    }).txGet();
    Set<BytesArray> result = new HashSet<BytesArray>();
    for (byte[] digests : response.existingDigests) {
        result.add(new BytesArray(digests));
    }
    return result;
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) HashSet(java.util.HashSet)

Example 7 with BytesArray

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

the class RemoteDigestBlob method chunk.

private Status chunk(ChannelBuffer buffer, boolean last) {
    assert transferId != null : "transferId should not be null";
    PutChunkRequest request = new PutChunkRequest(index, Hex.decodeHex(digest), transferId, new BytesArray(buffer.array()), size, last);
    size += buffer.readableBytes();
    PutChunkResponse putChunkResponse = client.execute(PutChunkAction.INSTANCE, request).actionGet();
    return putChunkResponse.status();
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray)

Example 8 with BytesArray

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

the class TransportShardUpsertAction method buildMapFromSource.

@VisibleForTesting
Map<String, Object> buildMapFromSource(Reference[] insertColumns, Object[] insertValues, boolean isRawSourceInsert) {
    Map<String, Object> sourceAsMap;
    if (isRawSourceInsert) {
        BytesRef source = (BytesRef) insertValues[0];
        sourceAsMap = XContentHelper.convertToMap(new BytesArray(source), true).v2();
    } else {
        sourceAsMap = new LinkedHashMap<>(insertColumns.length);
        for (int i = 0; i < insertColumns.length; i++) {
            sourceAsMap.put(insertColumns[i].ident().columnIdent().fqn(), insertValues[i]);
        }
    }
    return sourceAsMap;
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) BytesRef(org.apache.lucene.util.BytesRef) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 9 with BytesArray

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

the class SearchHitTests method testHasSource.

public void testHasSource() {
    SearchHit searchHit = new SearchHit(randomInt());
    assertFalse(searchHit.hasSource());
    searchHit.sourceRef(new BytesArray("{}"));
    assertTrue(searchHit.hasSource());
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray)

Example 10 with BytesArray

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

the class StoredScriptsIT method testBasics.

public void testBasics() {
    assertAcked(client().admin().cluster().preparePutStoredScript().setLang(LANG).setId("foobar").setContent(new BytesArray("{\"script\":\"1\"}"), XContentType.JSON));
    String script = client().admin().cluster().prepareGetStoredScript(LANG, "foobar").get().getSource().getCode();
    assertNotNull(script);
    assertEquals("1", script);
    assertAcked(client().admin().cluster().prepareDeleteStoredScript().setId("foobar").setLang(LANG));
    StoredScriptSource source = client().admin().cluster().prepareGetStoredScript(LANG, "foobar").get().getSource();
    assertNull(source);
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> client().admin().cluster().preparePutStoredScript().setLang("lang#").setId("id#").setContent(new BytesArray("{}"), XContentType.JSON).get());
    assertEquals("Validation Failed: 1: id cannot contain '#' for stored script;" + "2: lang cannot contain '#' for stored script;", e.getMessage());
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray)

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