use of org.elasticsearch.action.search.SearchRequestBuilder in project sonarqube by SonarSource.
the class ProjectMeasuresIndex method search.
public SearchIdResult<String> search(ProjectMeasuresQuery query, SearchOptions searchOptions) {
SearchRequestBuilder requestBuilder = getClient().prepareSearch(INDEX_TYPE_PROJECT_MEASURES).setFetchSource(false).setFrom(searchOptions.getOffset()).setSize(searchOptions.getLimit());
BoolQueryBuilder esFilter = boolQuery();
Map<String, QueryBuilder> filters = createFilters(query);
filters.values().forEach(esFilter::must);
requestBuilder.setQuery(esFilter);
addFacets(requestBuilder, searchOptions, filters, query);
addSort(query, requestBuilder);
return new SearchIdResult<>(requestBuilder.get(), id -> id);
}
use of org.elasticsearch.action.search.SearchRequestBuilder in project sonarqube by SonarSource.
the class RuleIndex method search.
public SearchIdResult<RuleKey> search(RuleQuery query, SearchOptions options) {
SearchRequestBuilder esSearch = getClient().prepareSearch(INDEX_TYPE_RULE);
QueryBuilder qb = buildQuery(query);
Map<String, QueryBuilder> filters = buildFilters(query);
if (!options.getFacets().isEmpty()) {
for (AbstractAggregationBuilder aggregation : getFacets(query, options, qb, filters).values()) {
esSearch.addAggregation(aggregation);
}
}
setSorting(query, esSearch);
setPagination(options, esSearch);
BoolQueryBuilder fb = boolQuery();
for (QueryBuilder filterBuilder : filters.values()) {
fb.must(filterBuilder);
}
esSearch.setQuery(boolQuery().must(qb).filter(fb));
return new SearchIdResult<>(esSearch.get(), ToRuleKey.INSTANCE);
}
use of org.elasticsearch.action.search.SearchRequestBuilder in project sonarqube by SonarSource.
the class ActiveRuleIndex method getStatsByProfileKeys.
public Map<String, Multimap<String, FacetValue>> getStatsByProfileKeys(List<String> keys) {
SearchRequestBuilder request = getClient().prepareSearch(INDEX_TYPE_RULE.getIndex()).setQuery(QueryBuilders.boolQuery().must(QueryBuilders.termsQuery(FIELD_ACTIVE_RULE_PROFILE_KEY, keys)).filter(QueryBuilders.boolQuery().mustNot(QueryBuilders.hasParentQuery(INDEX_TYPE_RULE.getType(), QueryBuilders.termQuery(FIELD_RULE_STATUS, RuleStatus.REMOVED.name()))))).addAggregation(AggregationBuilders.terms(FIELD_ACTIVE_RULE_PROFILE_KEY).field(RuleIndexDefinition.FIELD_ACTIVE_RULE_PROFILE_KEY).size(0).subAggregation(AggregationBuilders.terms(FIELD_ACTIVE_RULE_INHERITANCE).field(RuleIndexDefinition.FIELD_ACTIVE_RULE_INHERITANCE)).subAggregation(AggregationBuilders.terms(FIELD_ACTIVE_RULE_SEVERITY).field(RuleIndexDefinition.FIELD_ACTIVE_RULE_SEVERITY)).subAggregation(AggregationBuilders.count(COUNT_ACTIVE_RULES))).setSize(0);
SearchResponse response = request.get();
Map<String, Multimap<String, FacetValue>> stats = new HashMap<>();
Aggregation aggregation = response.getAggregations().get(FIELD_ACTIVE_RULE_PROFILE_KEY);
for (Terms.Bucket value : ((Terms) aggregation).getBuckets()) {
stats.put(value.getKeyAsString(), processAggregations(value.getAggregations()));
}
return stats;
}
use of org.elasticsearch.action.search.SearchRequestBuilder in project sonarqube by SonarSource.
the class ActiveRuleIndexer method deleteKeys.
private void deleteKeys(List<ActiveRuleKey> keys) {
BulkIndexer bulk = new BulkIndexer(esClient, INDEX_TYPE_ACTIVE_RULE.getIndex());
bulk.start();
SearchRequestBuilder search = esClient.prepareSearch(INDEX_TYPE_ACTIVE_RULE).setQuery(QueryBuilders.boolQuery().must(termsQuery(FIELD_ACTIVE_RULE_KEY, keys)));
bulk.addDeletion(search);
bulk.stop();
}
use of org.elasticsearch.action.search.SearchRequestBuilder in project sonarqube by SonarSource.
the class ActiveRuleIndexer method deleteProfile.
public void deleteProfile(String qualityProfileKey) {
BulkIndexer bulk = new BulkIndexer(esClient, INDEX_TYPE_ACTIVE_RULE.getIndex());
bulk.start();
SearchRequestBuilder search = esClient.prepareSearch(INDEX_TYPE_ACTIVE_RULE).setQuery(QueryBuilders.boolQuery().must(termsQuery(FIELD_ACTIVE_RULE_PROFILE_KEY, qualityProfileKey)));
bulk.addDeletion(search);
bulk.stop();
}
Aggregations