use of org.elasticsearch.action.get.GetRequest in project pinpoint by naver.
the class ElasticsearchExecutorInterceptor method recordeESattributes.
// TODO max dsl limit need
private void recordeESattributes(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
if (recordESVersion) {
if (target instanceof ClusterInfoAccessor) {
// record elasticsearch version and cluster name.
recorder.recordAttribute(ElasticsearchConstants.ARGS_VERSION_ANNOTATION_KEY, ((ClusterInfoAccessor) target)._$PINPOINT$_getClusterInfo());
}
}
if (recordDsl) {
if (args[0] instanceof SearchRequest) {
SearchRequest request = (SearchRequest) args[0];
recorder.recordAttribute(ElasticsearchConstants.ARGS_DSL_ANNOTATION_KEY, StringUtils.abbreviate(request.source().toString(), 256));
} else if (args[0] instanceof GetRequest) {
// GetRequest request = (GetRequest) args[0];
recorder.recordAttribute(ElasticsearchConstants.ARGS_DSL_ANNOTATION_KEY, StringUtils.abbreviate(args[0].toString(), 256));
} else if (args[0] instanceof IndexRequest) {
// IndexRequest request = (IndexRequest) args[0];
recorder.recordAttribute(ElasticsearchConstants.ARGS_DSL_ANNOTATION_KEY, StringUtils.abbreviate(args[0].toString(), 256));
} else if (args[0] instanceof DeleteRequest) {
// DeleteRequest request = (DeleteRequest) args[0];
recorder.recordAttribute(ElasticsearchConstants.ARGS_DSL_ANNOTATION_KEY, StringUtils.abbreviate(args[0].toString(), 256));
} else if (args[0] instanceof UpdateRequest) {
// UpdateRequest request = (UpdateRequest) args[0];
recorder.recordAttribute(ElasticsearchConstants.ARGS_DSL_ANNOTATION_KEY, StringUtils.abbreviate(args[0].toString(), 256));
}
}
}
use of org.elasticsearch.action.get.GetRequest in project gora by apache.
the class ElasticsearchStore method exists.
@Override
public boolean exists(K key) throws GoraException {
GetRequest getRequest = new GetRequest(elasticsearchMapping.getIndexName(), (String) key);
getRequest.fetchSourceContext(new FetchSourceContext(false)).storedFields("_none_");
try {
return client.exists(getRequest, RequestOptions.DEFAULT);
} catch (IOException ex) {
throw new GoraException(ex);
}
}
use of org.elasticsearch.action.get.GetRequest in project graylog2-server by Graylog2.
the class MessagesAdapterES7 method get.
@Override
public ResultMessage get(String messageId, String index) throws DocumentNotFoundException {
final GetRequest getRequest = new GetRequest(index, messageId);
final GetResponse result = this.client.execute((c, requestOptions) -> c.get(getRequest, requestOptions));
if (!result.isExists()) {
throw new DocumentNotFoundException(index, messageId);
}
return ResultMessage.parseFromSource(messageId, index, result.getSource());
}
use of org.elasticsearch.action.get.GetRequest in project vorto by eclipse.
the class ElasticSearchService method modelIndexExist.
@SuppressWarnings("unused")
private boolean modelIndexExist(ModelId modelId) {
PreConditions.notNull(modelId, "modelId must not be null.");
GetRequest getRequest = new GetRequest(VORTO_INDEX, DOC, modelId.getPrettyFormat());
getRequest.fetchSourceContext(new FetchSourceContext(false));
getRequest.storedFields("_none_");
try {
return client.exists(getRequest, RequestOptions.DEFAULT);
} catch (IOException e) {
throw new IndexingException(String.format("Error while querying if model '%s' exist.", modelId.getPrettyFormat()), e);
}
}
use of org.elasticsearch.action.get.GetRequest in project incubator-gobblin by apache.
the class ElasticsearchWriterIntegrationTest method testMalformedDocs.
/**
* Sends two docs in a single batch with different field types
* Triggers Elasticsearch server to send back an exception due to malformed docs
* @throws IOException
*/
public void testMalformedDocs(WriterVariant writerVariant, RecordTypeGenerator recordVariant, MalformedDocPolicy malformedDocPolicy) throws IOException {
String indexName = writerVariant.getName().toLowerCase();
String indexType = (recordVariant.getName() + malformedDocPolicy.name()).toLowerCase();
Config config = writerVariant.getConfigBuilder().setIdMappingEnabled(true).setIndexName(indexName).setIndexType(indexType).setHttpPort(_esTestServer.getHttpPort()).setTransportPort(_esTestServer.getTransportPort()).setTypeMapperClassName(recordVariant.getTypeMapperClassName()).setMalformedDocPolicy(malformedDocPolicy).build();
TestClient testClient = writerVariant.getTestClient(config);
testClient.recreateIndex(indexName);
String id1 = TestUtils.generateRandomAlphaString(10);
String id2 = TestUtils.generateRandomAlphaString(10);
Object testRecord1 = recordVariant.getRecord(id1, PayloadType.LONG);
Object testRecord2 = recordVariant.getRecord(id2, PayloadType.MAP);
SequentialBasedBatchAccumulator<Object> batchAccumulator = new SequentialBasedBatchAccumulator<>(config);
BatchAsyncDataWriter elasticsearchWriter = writerVariant.getBatchAsyncDataWriter(config);
BufferedAsyncDataWriter bufferedAsyncDataWriter = new BufferedAsyncDataWriter(batchAccumulator, elasticsearchWriter);
DataWriter writer = AsyncWriterManager.builder().failureAllowanceRatio(0.0).retriesEnabled(false).config(config).asyncDataWriter(bufferedAsyncDataWriter).build();
try {
writer.write(testRecord1);
writer.write(testRecord2);
writer.commit();
writer.close();
if (malformedDocPolicy == MalformedDocPolicy.FAIL) {
Assert.fail("Should have thrown an exception if malformed doc policy was set to Fail");
}
} catch (Exception e) {
switch(malformedDocPolicy) {
case IGNORE:
case WARN:
{
Assert.fail("Should not have failed if malformed doc policy was set to ignore or warn", e);
break;
}
case FAIL:
{
// pass through
break;
}
default:
{
throw new RuntimeException("This test does not handle this policyType : " + malformedDocPolicy.toString());
}
}
}
// Irrespective of policy, first doc should be inserted and second doc should fail
int docsIndexed = 0;
try {
{
GetResponse response = testClient.get(new GetRequest(indexName, indexType, id1));
Assert.assertEquals(response.getId(), id1, "Response id matches request");
System.out.println(malformedDocPolicy + ":" + response.toString());
if (response.isExists()) {
docsIndexed++;
}
}
{
GetResponse response = testClient.get(new GetRequest(indexName, indexType, id2));
Assert.assertEquals(response.getId(), id2, "Response id matches request");
System.out.println(malformedDocPolicy + ":" + response.toString());
if (response.isExists()) {
docsIndexed++;
}
}
// only one doc should be found
Assert.assertEquals(docsIndexed, 1, "Only one document should be indexed");
} catch (Exception e) {
Assert.fail("Failed to get a response", e);
} finally {
testClient.close();
}
}
Aggregations