Search in sources :

Example 1 with Expression

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

the class ElasticSearchRestDAOV5 method getTaskExecutionLogs.

@Override
public List<TaskExecLog> getTaskExecutionLogs(String taskId) {
    try {
        // Build Query
        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);
        // Create the searchObjectIdsViaExpression source
        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        searchSourceBuilder.query(fq);
        searchSourceBuilder.sort(new FieldSortBuilder("createdTime").order(SortOrder.ASC));
        searchSourceBuilder.size(config.getElasticSearchTasklogLimit());
        // Generate the actual request to send to ES.
        SearchRequest searchRequest = new SearchRequest(logIndexPrefix + "*");
        searchRequest.types(LOG_DOC_TYPE);
        searchRequest.source(searchSourceBuilder);
        SearchResponse response = elasticSearchClient.search(searchRequest);
        SearchHit[] hits = response.getHits().getHits();
        List<TaskExecLog> logs = new ArrayList<>(hits.length);
        for (SearchHit hit : hits) {
            String source = hit.getSourceAsString();
            TaskExecLog tel = objectMapper.readValue(source, TaskExecLog.class);
            logs.add(tel);
        }
        return logs;
    } catch (Exception e) {
        logger.error("Failed to get task execution logs for task: {}", taskId, e);
    }
    return null;
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) SearchHit(org.elasticsearch.search.SearchHit) TaskExecLog(com.netflix.conductor.common.metadata.tasks.TaskExecLog) ArrayList(java.util.ArrayList) FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) QueryStringQueryBuilder(org.elasticsearch.index.query.QueryStringQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) 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) Expression(com.netflix.conductor.dao.es5.index.query.parser.Expression) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) QueryStringQueryBuilder(org.elasticsearch.index.query.QueryStringQueryBuilder)

Example 2 with Expression

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

the class ElasticSearchRestDAOV5 method searchObjectIdsViaExpression.

private SearchResult<String> searchObjectIdsViaExpression(String structuredQuery, int start, int size, List<String> sortOptions, String freeTextQuery, String docType) {
    try {
        // Build query
        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);
        return searchObjectIds(indexName, fq, start, size, sortOptions, docType);
    } catch (Exception e) {
        throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, e.getMessage(), e);
    }
}
Also used : ApplicationException(com.netflix.conductor.core.execution.ApplicationException) 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) ResponseException(org.elasticsearch.client.ResponseException) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException)

Example 3 with Expression

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

the class ElasticSearchRestDAOV5 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 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(EVENT_DOC_TYPE);
        searchRequest.source(searchSourceBuilder);
        SearchResponse response = elasticSearchClient.search(searchRequest);
        return mapEventExecutionsResponse(response);
    } catch (Exception e) {
        logger.error("Failed to get executions for event: {}", event, 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 4 with Expression

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

the class TestElasticSearchRestDAOV5 method searchObjectIdsViaExpression.

private SearchResponse searchObjectIdsViaExpression(String indexName, String structuredQuery, int start, int size, List<String> sortOptions, String freeTextQuery, String docType) throws ParserException, IOException {
    // Build query
    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);
    return searchObjectIds(indexName, fq, start, size, sortOptions, docType);
}
Also used : 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)

Example 5 with Expression

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

the class TestElasticSearchDAOV5 method search.

private SearchResponse search(String indexName, String structuredQuery, int start, int size, String freeTextQuery, String docType) throws ParserException {
    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);
    return srb.get();
}
Also used : 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)

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