Search in sources :

Example 11 with Expression

use of com.netflix.conductor.dao.es6.index.query.parser.Expression in project conductor by Netflix.

the class ElasticSearchDAOV5 method getTaskExecutionLogs.

@Override
public List<TaskExecLog> getTaskExecutionLogs(String taskId) {
    try {
        Expression expression = Expression.fromString("taskId='" + taskId + "'");
        QueryBuilder queryBuilder = expression.getFilterBuilder();
        BoolQueryBuilder filterQuery = QueryBuilders.boolQuery().must(queryBuilder);
        QueryStringQueryBuilder stringQuery = QueryBuilders.queryStringQuery("*");
        BoolQueryBuilder fq = QueryBuilders.boolQuery().must(stringQuery).must(filterQuery);
        FieldSortBuilder sortBuilder = SortBuilders.fieldSort("createdTime").order(SortOrder.ASC);
        final SearchRequestBuilder srb = elasticSearchClient.prepareSearch(logIndexPrefix + "*").setQuery(fq).setTypes(LOG_DOC_TYPE).addSort(sortBuilder).setSize(config.getElasticSearchTasklogLimit());
        SearchResponse response = srb.execute().actionGet();
        return Arrays.stream(response.getHits().getHits()).map(hit -> {
            String source = hit.getSourceAsString();
            try {
                return objectMapper.readValue(source, TaskExecLog.class);
            } catch (IOException e) {
                logger.error("exception deserializing taskExecLog: {}", source);
            }
            return null;
        }).filter(Objects::nonNull).collect(Collectors.toList());
    } catch (Exception e) {
        logger.error("Failed to get task execution logs for task: {}", taskId, e);
    }
    return null;
}
Also used : SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) 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) IOException(java.io.IOException) 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) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 12 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.es6.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)

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