Search in sources :

Example 6 with Expression

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);
}
Also used : Expression(com.netflix.conductor.dao.es7.index.query.parser.Expression) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) QueryStringQueryBuilder(org.elasticsearch.index.query.QueryStringQueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) QueryStringQueryBuilder(org.elasticsearch.index.query.QueryStringQueryBuilder)

Example 7 with Expression

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);
    }
}
Also used : ApplicationException(com.netflix.conductor.core.execution.ApplicationException) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) Expression(com.netflix.conductor.dao.es5.index.query.parser.Expression) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) QueryStringQueryBuilder(org.elasticsearch.index.query.QueryStringQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) QueryStringQueryBuilder(org.elasticsearch.index.query.QueryStringQueryBuilder) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) ParserException(com.netflix.conductor.elasticsearch.query.parser.ParserException) ResourceAlreadyExistsException(org.elasticsearch.ResourceAlreadyExistsException) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) IOException(java.io.IOException)

Example 8 with Expression

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);
    }
}
Also used : ParserException(com.netflix.conductor.elasticsearch.query.parser.ParserException) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) Expression(com.netflix.conductor.dao.es5.index.query.parser.Expression) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) SearchResult(com.netflix.conductor.common.run.SearchResult) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) QueryStringQueryBuilder(org.elasticsearch.index.query.QueryStringQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) QueryStringQueryBuilder(org.elasticsearch.index.query.QueryStringQueryBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 9 with Expression

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);
    }
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Expression(com.netflix.conductor.dao.es5.index.query.parser.Expression) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) QueryStringQueryBuilder(org.elasticsearch.index.query.QueryStringQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) QueryStringQueryBuilder(org.elasticsearch.index.query.QueryStringQueryBuilder) ResponseException(org.elasticsearch.client.ResponseException) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 10 with Expression

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);
    }
}
Also used : ApplicationException(com.netflix.conductor.core.execution.ApplicationException) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) Expression(com.netflix.conductor.dao.es5.index.query.parser.Expression) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) QueryStringQueryBuilder(org.elasticsearch.index.query.QueryStringQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) QueryStringQueryBuilder(org.elasticsearch.index.query.QueryStringQueryBuilder) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) ParserException(com.netflix.conductor.elasticsearch.query.parser.ParserException) ResourceAlreadyExistsException(org.elasticsearch.ResourceAlreadyExistsException) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) IOException(java.io.IOException)

Aggregations

BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)12 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)12 QueryStringQueryBuilder (org.elasticsearch.index.query.QueryStringQueryBuilder)12 Expression (com.netflix.conductor.dao.es5.index.query.parser.Expression)10 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)8 IOException (java.io.IOException)7 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)5 SearchResponse (org.elasticsearch.action.search.SearchResponse)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 ParserException (com.netflix.conductor.elasticsearch.query.parser.ParserException)4 ResponseException (org.elasticsearch.client.ResponseException)4 FieldSortBuilder (org.elasticsearch.search.sort.FieldSortBuilder)4 ResourceAlreadyExistsException (org.elasticsearch.ResourceAlreadyExistsException)3 SearchRequest (org.elasticsearch.action.search.SearchRequest)3 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)3 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)3 TaskExecLog (com.netflix.conductor.common.metadata.tasks.TaskExecLog)1 SearchResult (com.netflix.conductor.common.run.SearchResult)1 Expression (com.netflix.conductor.dao.es6.index.query.parser.Expression)1 Expression (com.netflix.conductor.dao.es7.index.query.parser.Expression)1