Search in sources :

Example 1 with ParserException

use of com.netflix.conductor.elasticsearch.query.parser.ParserException in project conductor by Netflix.

the class ElasticSearchDAOV6 method search.

private SearchResult<String> search(String structuredQuery, int start, int size, List<String> sortOptions, String freeTextQuery, String docType) {
    try {
        docType = StringUtils.isBlank(docTypeOverride) ? docType : docTypeOverride;
        BoolQueryBuilder fq = boolQueryBuilder(structuredQuery, freeTextQuery);
        final SearchRequestBuilder srb = elasticSearchClient.prepareSearch(getIndexName(docType)).setQuery(fq).setTypes(docType).storedFields("_id").setFrom(start).setSize(size);
        addSortOptions(srb, sortOptions);
        return mapSearchResult(srb.get());
    } catch (ParserException e) {
        throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, e.getMessage(), e);
    }
}
Also used : ParserException(com.netflix.conductor.elasticsearch.query.parser.ParserException) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder)

Example 2 with ParserException

use of com.netflix.conductor.elasticsearch.query.parser.ParserException 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)

Aggregations

ApplicationException (com.netflix.conductor.core.execution.ApplicationException)2 ParserException (com.netflix.conductor.elasticsearch.query.parser.ParserException)2 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)2 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)2 SearchResult (com.netflix.conductor.common.run.SearchResult)1 Expression (com.netflix.conductor.dao.es5.index.query.parser.Expression)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)1 QueryStringQueryBuilder (org.elasticsearch.index.query.QueryStringQueryBuilder)1