use of co.elastic.clients.elasticsearch._types.ElasticsearchException in project core-ng-project by neowu.
the class ElasticSearchTypeImpl method get.
@Override
public Optional<T> get(GetRequest request) {
var watch = new StopWatch();
String index = request.index == null ? this.index : request.index;
int hits = 0;
try {
GetResponse<T> response = elasticSearch.client.get(builder -> builder.index(index).id(request.id), documentClass);
if (!response.found())
return Optional.empty();
hits = 1;
return Optional.of(response.source());
} catch (IOException e) {
throw new UncheckedIOException(e);
} catch (ElasticsearchException e) {
throw elasticSearch.searchException(e);
} finally {
long elapsed = watch.elapsed();
ActionLogContext.track("elasticsearch", elapsed, hits, 0);
logger.debug("get, index={}, id={}, elapsed={}", index, request.id, elapsed);
checkSlowOperation(elapsed);
}
}
use of co.elastic.clients.elasticsearch._types.ElasticsearchException in project core-ng-project by neowu.
the class ElasticSearchTypeImpl method analyze.
@Override
public List<String> analyze(AnalyzeRequest request) {
var watch = new StopWatch();
String index = request.index == null ? this.index : request.index;
try {
AnalyzeResponse response = elasticSearch.client.indices().analyze(builder -> builder.index(index).analyzer(request.analyzer).text(request.text));
return response.tokens().stream().map(AnalyzeToken::token).toList();
} catch (IOException e) {
throw new UncheckedIOException(e);
} catch (ElasticsearchException e) {
throw elasticSearch.searchException(e);
} finally {
long elapsed = watch.elapsed();
ActionLogContext.track("elasticsearch", elapsed);
logger.debug("analyze, index={}, analyzer={}, elapsed={}", index, request.analyzer, elapsed);
checkSlowOperation(elapsed);
}
}
Aggregations