use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder in project ff4j by ff4j.
the class ElasticQueryBuilder method queryPropertyByName.
public Search queryPropertyByName(String name) {
SearchSourceBuilder source = new SearchSourceBuilder();
source.query(QueryBuilders.matchQuery("name", name));
return new Search.Builder(source.toString()).addIndex(connection.getIndexName()).addType(ElasticConstants.TYPE_PROPERTY).build();
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder in project nuxeo-drive-server by nuxeo.
the class ESAuditChangeFinder method getUpperBound.
@Override
public long getUpperBound() {
SearchRequest request = new SearchRequest(getESIndexName()).types(ElasticSearchConstants.ENTRY_TYPE).searchType(SearchType.DFS_QUERY_THEN_FETCH);
// TODO refactor this to use max clause
request.source(new SearchSourceBuilder().query(QueryBuilders.matchAllQuery()).sort("id", SortOrder.DESC).size(1));
logSearchRequest(request);
SearchResponse searchResponse = getClient().search(request);
logSearchResponse(searchResponse);
List<LogEntry> entries = new ArrayList<>();
SearchHits hits = searchResponse.getHits();
ObjectMapper mapper = new ObjectMapper();
for (SearchHit hit : hits) {
try {
entries.add(mapper.readValue(hit.getSourceAsString(), LogEntryImpl.class));
} catch (IOException e) {
log.error("Error while reading Audit Entry from ES", e);
}
}
return entries.size() > 0 ? entries.get(0).getId() : -1;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder 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.search.builder.SearchSourceBuilder 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.search.builder.SearchSourceBuilder 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