use of com.netflix.conductor.dao.es6.index.query.parser.Expression in project conductor by Netflix.
the class ElasticSearchBaseDAO method boolQueryBuilder.
BoolQueryBuilder boolQueryBuilder(String expression, String queryString) throws ParserException {
QueryBuilder queryBuilder = QueryBuilders.matchAllQuery();
if (StringUtils.isNotEmpty(expression)) {
Expression exp = Expression.fromString(expression);
queryBuilder = exp.getFilterBuilder();
}
BoolQueryBuilder filterQuery = QueryBuilders.boolQuery().must(queryBuilder);
QueryStringQueryBuilder stringQuery = QueryBuilders.queryStringQuery(queryString);
return QueryBuilders.boolQuery().must(stringQuery).must(filterQuery);
}
use of com.netflix.conductor.dao.es6.index.query.parser.Expression in project conductor by Netflix.
the class ElasticSearchDAOV5 method getEventExecutions.
@Override
public List<EventExecution> getEventExecutions(String event) {
try {
Expression expression = Expression.fromString("event='" + event + "'");
QueryBuilder queryBuilder = expression.getFilterBuilder();
BoolQueryBuilder filterQuery = QueryBuilders.boolQuery().must(queryBuilder);
QueryStringQueryBuilder stringQuery = QueryBuilders.queryStringQuery("*");
BoolQueryBuilder fq = QueryBuilders.boolQuery().must(stringQuery).must(filterQuery);
final SearchRequestBuilder srb = elasticSearchClient.prepareSearch(logIndexPrefix + "*").setQuery(fq).setTypes(EVENT_DOC_TYPE).addSort(SortBuilders.fieldSort("created").order(SortOrder.ASC));
return mapEventExecutionsResponse(srb.execute().actionGet());
} catch (Exception e) {
String errorMsg = String.format("Failed to get executions for event: %s", event);
logger.error(errorMsg, e);
throw new ApplicationException(Code.BACKEND_ERROR, errorMsg, e);
}
}
use of com.netflix.conductor.dao.es6.index.query.parser.Expression in project conductor by Netflix.
the class ElasticSearchDAOV5 method search.
private SearchResult<String> search(String indexName, String structuredQuery, int start, int size, List<String> sortOptions, String freeTextQuery, String docType) {
try {
QueryBuilder queryBuilder = QueryBuilders.matchAllQuery();
if (StringUtils.isNotEmpty(structuredQuery)) {
Expression expression = Expression.fromString(structuredQuery);
queryBuilder = expression.getFilterBuilder();
}
BoolQueryBuilder filterQuery = QueryBuilders.boolQuery().must(queryBuilder);
QueryStringQueryBuilder stringQuery = QueryBuilders.queryStringQuery(freeTextQuery);
BoolQueryBuilder fq = QueryBuilders.boolQuery().must(stringQuery).must(filterQuery);
final SearchRequestBuilder srb = elasticSearchClient.prepareSearch(indexName).setQuery(fq).setTypes(docType).storedFields("_id").setFrom(start).setSize(size);
if (sortOptions != null) {
sortOptions.forEach(sortOption -> addSortOptionToSearchRequest(srb, sortOption));
}
SearchResponse response = srb.get();
LinkedList<String> result = StreamSupport.stream(response.getHits().spliterator(), false).map(SearchHit::getId).collect(Collectors.toCollection(LinkedList::new));
long count = response.getHits().getTotalHits();
return new SearchResult<>(count, result);
} catch (ParserException e) {
String errorMsg = String.format("Error performing search on index:%s with docType:%s", indexName, docType);
logger.error(errorMsg);
throw new ApplicationException(Code.BACKEND_ERROR, errorMsg, e);
}
}
use of com.netflix.conductor.dao.es6.index.query.parser.Expression in project conductor by Netflix.
the class ElasticSearchRestDAOV5 method getMessages.
@Override
public List<Message> getMessages(String queue) {
try {
Expression expression = Expression.fromString("queue='" + queue + "'");
QueryBuilder queryBuilder = expression.getFilterBuilder();
BoolQueryBuilder filterQuery = QueryBuilders.boolQuery().must(queryBuilder);
QueryStringQueryBuilder stringQuery = QueryBuilders.queryStringQuery("*");
BoolQueryBuilder query = QueryBuilders.boolQuery().must(stringQuery).must(filterQuery);
// Create the searchObjectIdsViaExpression source
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(query);
searchSourceBuilder.sort(new FieldSortBuilder("created").order(SortOrder.ASC));
// Generate the actual request to send to ES.
SearchRequest searchRequest = new SearchRequest(logIndexPrefix + "*");
searchRequest.types(MSG_DOC_TYPE);
searchRequest.source(searchSourceBuilder);
SearchResponse response = elasticSearchClient.search(searchRequest);
return mapGetMessagesResponse(response);
} catch (Exception e) {
logger.error("Failed to get messages for queue: {}", queue, e);
throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, e.getMessage(), e);
}
}
use of com.netflix.conductor.dao.es6.index.query.parser.Expression in project conductor by Netflix.
the class ElasticSearchDAOV5 method getMessages.
@Override
public List<Message> getMessages(String queue) {
try {
Expression expression = Expression.fromString("queue='" + queue + "'");
QueryBuilder queryBuilder = expression.getFilterBuilder();
BoolQueryBuilder filterQuery = QueryBuilders.boolQuery().must(queryBuilder);
QueryStringQueryBuilder stringQuery = QueryBuilders.queryStringQuery("*");
BoolQueryBuilder fq = QueryBuilders.boolQuery().must(stringQuery).must(filterQuery);
final SearchRequestBuilder srb = elasticSearchClient.prepareSearch(logIndexPrefix + "*").setQuery(fq).setTypes(MSG_DOC_TYPE).addSort(SortBuilders.fieldSort("created").order(SortOrder.ASC));
return mapGetMessagesResponse(srb.execute().actionGet());
} catch (Exception e) {
String errorMsg = String.format("Failed to get messages for queue: %s", queue);
logger.error(errorMsg, e);
throw new ApplicationException(Code.BACKEND_ERROR, errorMsg, e);
}
}
Aggregations