use of com.enonic.xp.repo.impl.elasticsearch.query.ElasticsearchQuery 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();
}
use of com.enonic.xp.repo.impl.elasticsearch.query.ElasticsearchQuery in project xp by enonic.
the class CopyExecutor method execute.
public void execute() {
final ElasticsearchQuery query = createQuery();
final SearchRequestBuilder searchRequestBuilder = SearchRequestBuilderFactory.newFactory().query(query).client(this.client).resolvedSize(query.getBatchSize()).scrollTime(DEFAULT_SCROLL_TIME).build().createScrollRequest();
SearchResponse scrollResp = searchRequestBuilder.execute().actionGet();
while (true) {
LOG.debug("Copy: Fetched [" + scrollResp.getHits().hits().length + "] hits, processing");
if (scrollResp.getHits().getHits().length > 0) {
doCopy(scrollResp);
}
scrollResp = client.prepareSearchScroll(scrollResp.getScrollId()).setScroll(DEFAULT_SCROLL_TIME).execute().actionGet();
if (scrollResp.getHits().getHits().length == 0) {
clearScroll(scrollResp);
break;
}
}
}
use of com.enonic.xp.repo.impl.elasticsearch.query.ElasticsearchQuery in project xp by enonic.
the class SearchExecutor method execute.
public SearchResult execute(final SearchRequest searchRequest) {
final ElasticsearchQuery query = ESQueryTranslator.translate(searchRequest);
final SearchMode searchMode = query.getSearchMode();
final int size = query.getSize();
final boolean anyAggregations = !query.getAggregations().isEmpty();
if (searchMode.equals(SearchMode.COUNT)) {
return CountExecutor.create(this.client).build().execute(query);
}
if (size == NodeSearchService.GET_ALL_SIZE_FLAG) {
if (anyAggregations) {
LOG.debug("Query with size [" + query.getSize() + "] > threshold [" + SCROLL_THRESHOLD + "] but with aggregations. Scan not possible.");
} else {
return ScrollExecutor.create(this.client).build().execute(query);
}
}
return doSearch(query);
}
Aggregations