use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest in project jnosql-diana-driver by eclipse.
the class DefaultElasticsearchDocumentCollectionManagerAsync method search.
@Override
public void search(QueryBuilder query, Consumer<List<DocumentEntity>> callBack, String... types) {
requireNonNull(query, "query is required");
requireNonNull(callBack, "callBack is required");
SearchRequest searchRequest = new SearchRequest(index);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(query);
searchRequest.types(types);
client.searchAsync(searchRequest, new FindQueryBuilderListener(callBack));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest in project jnosql-diana-driver by eclipse.
the class EntityConverter method queryAsync.
static void queryAsync(DocumentQuery query, RestHighLevelClient client, String index, Consumer<List<DocumentEntity>> callBack) {
FindAsyncListener listener = new FindAsyncListener(callBack, query.getDocumentCollection());
QueryConverterResult select = QueryConverter.select(query);
if (!select.getIds().isEmpty()) {
MultiGetRequest multiGetRequest = new MultiGetRequest();
select.getIds().stream().map(id -> new MultiGetRequest.Item(index, query.getDocumentCollection(), id)).forEach(multiGetRequest::add);
client.multiGetAsync(multiGetRequest, listener.getIds());
}
if (select.hasStatement()) {
SearchRequest searchRequest = new SearchRequest(index);
searchRequest.types(query.getDocumentCollection());
if (select.hasQuery()) {
setQueryBuilder(query, select, searchRequest);
}
client.searchAsync(searchRequest, listener.getSearch());
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest in project jnosql-diana-driver by eclipse.
the class EntityConverter method executeStatement.
private static void executeStatement(DocumentQuery query, RestHighLevelClient client, String index, QueryConverterResult select, List<DocumentEntity> entities) throws IOException {
SearchRequest searchRequest = new SearchRequest(index);
searchRequest.types(query.getDocumentCollection());
if (select.hasQuery()) {
setQueryBuilder(query, select, searchRequest);
}
SearchResponse response = client.search(searchRequest);
Stream.of(response.getHits()).flatMap(h -> Stream.of(h.getHits())).map(ElasticsearchEntry::of).filter(ElasticsearchEntry::isNotEmpty).map(ElasticsearchEntry::toEntity).forEach(entities::add);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest in project main by JohnPeng739.
the class ElasticAccessorRest method search.
private <T extends Base> SearchResponse search(List<GeneralAccessor.ConditionTuple> tuples, Class<T> clazz, Pagination pagination) throws UserInterfaceDalErrorException {
SearchSourceBuilder builder = new SearchSourceBuilder();
if (tuples == null || tuples.isEmpty()) {
builder.query(QueryBuilders.matchAllQuery());
} else {
BoolQueryBuilder query = QueryBuilders.boolQuery();
tuples.forEach(tuple -> query.must(QueryBuilders.termQuery(tuple.field, tuple.value)));
builder.query(query);
}
if (pagination != null) {
builder.from((pagination.getPage() - 1) * pagination.getSize());
builder.size(pagination.getSize());
}
SearchRequest request = new SearchRequest(index);
request.types(clazz.getName());
request.source(builder);
try {
SearchResponse response = client.search(request);
return response;
} catch (Exception ex) {
if (logger.isErrorEnabled()) {
logger.error("Search fail from elastic.", ex);
}
throw new UserInterfaceDalErrorException(UserInterfaceDalErrorException.DalErrors.DB_OPERATE_FAIL);
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest in project logging-log4j2 by apache.
the class LogstashIT method queryDocuments.
private static List<Map<String, Object>> queryDocuments(final RestHighLevelClient client) throws IOException {
final SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(LOG_EVENT_COUNT).fetchSource(true);
final SearchRequest searchRequest = new SearchRequest(MavenHardcodedConstants.ES_INDEX_NAME).source(searchSourceBuilder);
try {
final SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
return Arrays.stream(searchResponse.getHits().getHits()).map(SearchHit::getSourceAsMap).collect(Collectors.toList());
} catch (ElasticsearchStatusException error) {
if (RestStatus.NOT_FOUND.equals(error.status())) {
return Collections.emptyList();
}
throw new IOException(error);
}
}
Aggregations