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()));
}
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));
}
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();
}
}
}
}
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();
}
};
}
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));
});
}
Aggregations