Search in sources :

Example 86 with GetResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project datashare by ICIJ.

the class ElasticsearchSpewerTest method test_metadata.

@Test
public void test_metadata() throws Exception {
    Path path = get(Objects.requireNonNull(getClass().getResource("/docs/a/b/c/doc.txt")).getPath());
    TikaDocument document = new Extractor().extract(path);
    spewer.write(document);
    GetResponse documentFields = es.client.get(new GetRequest(TEST_INDEX, document.getId()), RequestOptions.DEFAULT);
    assertThat(documentFields.getSourceAsMap()).includes(entry("contentEncoding", "ISO-8859-1"), entry("contentType", "text/plain"), entry("nerTags", new ArrayList<>()), entry("contentLength", 45), entry("status", "INDEXED"), entry("path", path.toString()), entry("dirname", path.getParent().toString()));
}
Also used : Path(java.nio.file.Path) GetRequest(org.elasticsearch.action.get.GetRequest) ArrayList(java.util.ArrayList) TikaDocument(org.icij.extract.document.TikaDocument) Extractor(org.icij.extract.extractor.Extractor) GetResponse(org.elasticsearch.action.get.GetResponse) Test(org.junit.Test)

Example 87 with GetResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project datashare by ICIJ.

the class ElasticsearchSpewerTest method test_long_content_length.

@Test
public void test_long_content_length() throws Exception {
    final TikaDocument document = new DocumentFactory().withIdentifier(new PathIdentifier()).create(get("t-file.txt"));
    final ParsingReader reader = new ParsingReader(new ByteArrayInputStream("test".getBytes()));
    document.setReader(reader);
    document.getMetadata().set("Content-Length", "7862117376");
    spewer.write(document);
    GetResponse documentFields = es.client.get(new GetRequest(TEST_INDEX, document.getId()), RequestOptions.DEFAULT);
    assertThat(documentFields.getSourceAsMap()).includes(entry("contentLength", 7862117376L));
}
Also used : DocumentFactory(org.icij.extract.document.DocumentFactory) ParsingReader(org.apache.tika.parser.ParsingReader) ByteArrayInputStream(java.io.ByteArrayInputStream) GetRequest(org.elasticsearch.action.get.GetRequest) PathIdentifier(org.icij.extract.document.PathIdentifier) TikaDocument(org.icij.extract.document.TikaDocument) GetResponse(org.elasticsearch.action.get.GetResponse) Test(org.junit.Test)

Example 88 with GetResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project incubator-gobblin by apache.

the class ElasticsearchWriterIntegrationTest method testSingleRecordWrite.

@Test
public void testSingleRecordWrite() throws IOException {
    for (WriterVariant writerVariant : variants) {
        for (RecordTypeGenerator recordVariant : recordGenerators) {
            String indexName = "posts" + writerVariant.getName().toLowerCase();
            String indexType = recordVariant.getName();
            Config config = writerVariant.getConfigBuilder().setIndexName(indexName).setIndexType(indexType).setTypeMapperClassName(recordVariant.getTypeMapperClassName()).setHttpPort(_esTestServer.getHttpPort()).setTransportPort(_esTestServer.getTransportPort()).build();
            TestClient testClient = writerVariant.getTestClient(config);
            SequentialBasedBatchAccumulator<Object> batchAccumulator = new SequentialBasedBatchAccumulator<>(config);
            BufferedAsyncDataWriter bufferedAsyncDataWriter = new BufferedAsyncDataWriter(batchAccumulator, writerVariant.getBatchAsyncDataWriter(config));
            String id = TestUtils.generateRandomAlphaString(10);
            Object testRecord = recordVariant.getRecord(id, PayloadType.STRING);
            DataWriter writer = AsyncWriterManager.builder().failureAllowanceRatio(0.0).retriesEnabled(false).config(config).asyncDataWriter(bufferedAsyncDataWriter).build();
            try {
                testClient.recreateIndex(indexName);
                writer.write(testRecord);
                writer.commit();
            } finally {
                writer.close();
            }
            try {
                GetResponse response = testClient.get(new GetRequest(indexName, indexType, id));
                Assert.assertEquals(response.getId(), id, "Response id matches request");
                Assert.assertEquals(response.isExists(), true, "Document not found");
            } catch (Exception e) {
                Assert.fail("Failed to get a response", e);
            } finally {
                testClient.close();
            }
        }
    }
}
Also used : Config(com.typesafe.config.Config) BufferedAsyncDataWriter(org.apache.gobblin.writer.BufferedAsyncDataWriter) SequentialBasedBatchAccumulator(org.apache.gobblin.writer.SequentialBasedBatchAccumulator) GetResponse(org.elasticsearch.action.get.GetResponse) IOException(java.io.IOException) GetRequest(org.elasticsearch.action.get.GetRequest) RecordTypeGenerator(org.apache.gobblin.test.RecordTypeGenerator) DataWriter(org.apache.gobblin.writer.DataWriter) BufferedAsyncDataWriter(org.apache.gobblin.writer.BufferedAsyncDataWriter) BatchAsyncDataWriter(org.apache.gobblin.writer.BatchAsyncDataWriter) Test(org.testng.annotations.Test)

Example 89 with GetResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project incubator-gobblin by apache.

the class RestWriterVariant method getTestClient.

@Override
public TestClient getTestClient(Config config) throws IOException {
    final ElasticsearchRestWriter restWriter = new ElasticsearchRestWriter(config);
    final RestHighLevelClient highLevelClient = restWriter.getRestHighLevelClient();
    return new TestClient() {

        @Override
        public GetResponse get(GetRequest getRequest) throws IOException {
            return highLevelClient.get(getRequest);
        }

        @Override
        public void recreateIndex(String indexName) throws IOException {
            RestClient restClient = restWriter.getRestLowLevelClient();
            try {
                restClient.performRequest("DELETE", "/" + indexName);
            } catch (Exception e) {
            // ok since index may not exist
            }
            String indexSettings = "{\"settings\" : {\"index\":{\"number_of_shards\":1,\"number_of_replicas\":1}}}";
            HttpEntity entity = new StringEntity(indexSettings, ContentType.APPLICATION_JSON);
            Response putResponse = restClient.performRequest("PUT", "/" + indexName, Collections.emptyMap(), entity);
            Assert.assertEquals(putResponse.getStatusLine().getStatusCode(), 200, "Recreate index succeeded");
        }

        @Override
        public void close() throws IOException {
            restWriter.close();
        }
    };
}
Also used : GetResponse(org.elasticsearch.action.get.GetResponse) Response(org.elasticsearch.client.Response) StringEntity(org.apache.http.entity.StringEntity) HttpEntity(org.apache.http.HttpEntity) GetRequest(org.elasticsearch.action.get.GetRequest) RestClient(org.elasticsearch.client.RestClient) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) IOException(java.io.IOException)

Example 90 with GetResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project crate by crate.

the class GetResponseRefResolver method getImplementation.

@Override
public CollectExpression<GetResponse, ?> getImplementation(Reference ref) {
    ColumnIdent columnIdent = ref.ident().columnIdent();
    columnConsumer.accept(columnIdent);
    String fqn = columnIdent.fqn();
    switch(fqn) {
        case DocSysColumns.Names.VERSION:
            return CollectExpression.of(GetResponse::getVersion);
        case DocSysColumns.Names.ID:
            return CollectExpression.of(GetResponse::getId);
        case DocSysColumns.Names.RAW:
            return CollectExpression.of(r -> r.getSourceAsBytesRef().toBytesRef());
        case DocSysColumns.Names.DOC:
            return CollectExpression.of(GetResponse::getSource);
    }
    if (docTableInfo.isPartitioned() && docTableInfo.partitionedBy().contains(columnIdent)) {
        int pkPos = docTableInfo.primaryKey().indexOf(columnIdent);
        if (pkPos >= 0) {
            return CollectExpression.of(response -> ValueSymbolVisitor.VALUE.process(ids2Keys.get(response.getId()).values().get(pkPos)));
        }
    }
    return CollectExpression.of(response -> {
        Map<String, Object> sourceAsMap = response.getSourceAsMap();
        return ref.valueType().value(XContentMapValues.extractValue(fqn, sourceAsMap));
    });
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) GetResponse(org.elasticsearch.action.get.GetResponse)

Aggregations

GetResponse (org.elasticsearch.action.get.GetResponse)167 Test (org.junit.Test)50 GetRequest (org.elasticsearch.action.get.GetRequest)28 Map (java.util.Map)27 MultiGetResponse (org.elasticsearch.action.get.MultiGetResponse)26 ArrayList (java.util.ArrayList)23 HashMap (java.util.HashMap)21 Date (java.util.Date)18 ESSyncConfig (com.alibaba.otter.canal.client.adapter.es.core.config.ESSyncConfig)17 Dml (com.alibaba.otter.canal.client.adapter.support.Dml)17 LinkedHashMap (java.util.LinkedHashMap)17 IOException (java.io.IOException)16 DataSource (javax.sql.DataSource)14 GetRequestBuilder (org.elasticsearch.action.get.GetRequestBuilder)14 SearchResponse (org.elasticsearch.action.search.SearchResponse)14 DeleteResponse (org.elasticsearch.action.delete.DeleteResponse)12 ElasticsearchException (org.elasticsearch.ElasticsearchException)10 Settings (org.elasticsearch.common.settings.Settings)10 Alias (org.elasticsearch.action.admin.indices.alias.Alias)7 IndexResponse (org.elasticsearch.action.index.IndexResponse)7