Search in sources :

Example 1 with FilterBuilderFactory

use of com.enonic.xp.repo.impl.elasticsearch.query.translator.factory.FilterBuilderFactory in project xp by enonic.

the class ESQueryTranslator method doTranslate.

private static ElasticsearchQuery doTranslate(final SearchRequest request, final QueryTypeTranslator queryTypeTranslator) {
    final ESSource esSource = ESSourceFactory.create(request.getSearchSource());
    final QueryBuilder queryBuilder = queryTypeTranslator.createQueryBuilder(esSource.getFilters());
    final Query query = request.getQuery();
    final Set<AbstractAggregationBuilder> aggregations = new AggregationQueryBuilderFactory(queryTypeTranslator.getFieldNameResolver()).create(query.getAggregationQueries());
    final Set<SuggestBuilder.SuggestionBuilder> suggestions = new SuggestionQueryBuilderFactory(queryTypeTranslator.getFieldNameResolver()).create(query.getSuggestionQueries());
    final ElasticHighlightQuery highlight = new ElasticHighlightQueryBuilderFactory().create(query.getHighlight());
    final List<SortBuilder> sortBuilders = new SortQueryBuilderFactory(queryTypeTranslator.getFieldNameResolver()).create(query.getOrderBys());
    final QueryBuilder filterBuilder = new FilterBuilderFactory(queryTypeTranslator.getFieldNameResolver()).create(query.getPostFilters());
    return ElasticsearchQuery.create().addIndexNames(esSource.getIndexNames()).addIndexTypes(esSource.getIndexTypes()).query(queryBuilder).from(query.getFrom()).size(query.getSize()).explain(query.isExplain()).setReturnFields(request.getReturnFields()).setAggregations(aggregations).setSuggestions(suggestions).setHighlight(highlight).sortBuilders(sortBuilders).filter(filterBuilder).batchSize(queryTypeTranslator.getBatchSize()).searchMode(query.getSearchMode()).searchOptimizer(queryTypeTranslator.getSearchOptimizer()).searchPreference(request.getSearchPreference()).build();
}
Also used : SortBuilder(org.elasticsearch.search.sort.SortBuilder) ESSource(com.enonic.xp.repo.impl.elasticsearch.query.source.ESSource) NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) NodeVersionDiffQuery(com.enonic.xp.repo.impl.version.search.NodeVersionDiffQuery) ElasticHighlightQuery(com.enonic.xp.repo.impl.elasticsearch.query.ElasticHighlightQuery) ElasticsearchQuery(com.enonic.xp.repo.impl.elasticsearch.query.ElasticsearchQuery) NodeCommitQuery(com.enonic.xp.node.NodeCommitQuery) Query(com.enonic.xp.query.Query) NodeQuery(com.enonic.xp.node.NodeQuery) NodeBranchQuery(com.enonic.xp.repo.impl.branch.search.NodeBranchQuery) AbstractAggregationBuilder(org.elasticsearch.search.aggregations.AbstractAggregationBuilder) ElasticHighlightQuery(com.enonic.xp.repo.impl.elasticsearch.query.ElasticHighlightQuery) SuggestionQueryBuilderFactory(com.enonic.xp.repo.impl.elasticsearch.suggistion.query.SuggestionQueryBuilderFactory) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) FilterBuilderFactory(com.enonic.xp.repo.impl.elasticsearch.query.translator.factory.FilterBuilderFactory) ElasticHighlightQueryBuilderFactory(com.enonic.xp.repo.impl.elasticsearch.highlight.ElasticHighlightQueryBuilderFactory) SortQueryBuilderFactory(com.enonic.xp.repo.impl.elasticsearch.query.translator.factory.SortQueryBuilderFactory) AggregationQueryBuilderFactory(com.enonic.xp.repo.impl.elasticsearch.aggregation.query.AggregationQueryBuilderFactory)

Example 2 with FilterBuilderFactory

use of com.enonic.xp.repo.impl.elasticsearch.query.translator.factory.FilterBuilderFactory in project xp by enonic.

the class CopyExecutor method createQuery.

private ElasticsearchQuery createQuery() {
    final IdFilter idFilter = IdFilter.create().fieldName(NodeIndexPath.ID.getPath()).values(copyRequest.getNodeIds()).build();
    final QueryBuilder idFilterBuilder = new FilterBuilderFactory(new SearchQueryFieldNameResolver()).create(Filters.from(idFilter));
    QueryBuilder query = QueryBuilders.matchAllQuery();
    return ElasticsearchQuery.create().query(QueryBuilders.filteredQuery(query, idFilterBuilder)).addIndexName(copyRequest.getStorageSource().getStorageName().getName()).addIndexType(copyRequest.getStorageSource().getStorageType().getName()).size(copyRequest.getNodeIds().getSize()).batchSize(BATCH_SIZE).from(0).setReturnFields(ReturnFields.from(NodeIndexPath.SOURCE)).build();
}
Also used : IdFilter(com.enonic.xp.query.filter.IdFilter) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) SearchQueryFieldNameResolver(com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver) FilterBuilderFactory(com.enonic.xp.repo.impl.elasticsearch.query.translator.factory.FilterBuilderFactory)

Aggregations

FilterBuilderFactory (com.enonic.xp.repo.impl.elasticsearch.query.translator.factory.FilterBuilderFactory)2 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)2 NodeCommitQuery (com.enonic.xp.node.NodeCommitQuery)1 NodeQuery (com.enonic.xp.node.NodeQuery)1 NodeVersionQuery (com.enonic.xp.node.NodeVersionQuery)1 Query (com.enonic.xp.query.Query)1 IdFilter (com.enonic.xp.query.filter.IdFilter)1 NodeBranchQuery (com.enonic.xp.repo.impl.branch.search.NodeBranchQuery)1 AggregationQueryBuilderFactory (com.enonic.xp.repo.impl.elasticsearch.aggregation.query.AggregationQueryBuilderFactory)1 ElasticHighlightQueryBuilderFactory (com.enonic.xp.repo.impl.elasticsearch.highlight.ElasticHighlightQueryBuilderFactory)1 ElasticHighlightQuery (com.enonic.xp.repo.impl.elasticsearch.query.ElasticHighlightQuery)1 ElasticsearchQuery (com.enonic.xp.repo.impl.elasticsearch.query.ElasticsearchQuery)1 ESSource (com.enonic.xp.repo.impl.elasticsearch.query.source.ESSource)1 SortQueryBuilderFactory (com.enonic.xp.repo.impl.elasticsearch.query.translator.factory.SortQueryBuilderFactory)1 SearchQueryFieldNameResolver (com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver)1 SuggestionQueryBuilderFactory (com.enonic.xp.repo.impl.elasticsearch.suggistion.query.SuggestionQueryBuilderFactory)1 NodeVersionDiffQuery (com.enonic.xp.repo.impl.version.search.NodeVersionDiffQuery)1 AbstractAggregationBuilder (org.elasticsearch.search.aggregations.AbstractAggregationBuilder)1 SortBuilder (org.elasticsearch.search.sort.SortBuilder)1