use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder in project sonarqube by SonarSource.
the class RuleIndex method search.
public SearchIdResult<String> search(RuleQuery query, SearchOptions options) {
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
QueryBuilder qb = buildQuery(query);
Map<String, QueryBuilder> filters = buildFilters(query);
if (!options.getFacets().isEmpty()) {
for (AggregationBuilder aggregation : getFacets(query, options, qb, filters).values()) {
sourceBuilder.aggregation(aggregation);
}
}
setSorting(query, sourceBuilder);
setPagination(options, sourceBuilder);
BoolQueryBuilder fb = boolQuery();
for (QueryBuilder filterBuilder : filters.values()) {
fb.must(filterBuilder);
}
sourceBuilder.query(boolQuery().must(qb).filter(fb));
SearchRequest esSearch = EsClient.prepareSearch(TYPE_RULE).source(sourceBuilder);
return new SearchIdResult<>(client.search(esSearch), input -> input, system2.getDefaultTimeZone().toZoneId());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder in project sonarqube by SonarSource.
the class RuleIndex method listTags.
public List<String> listTags(@Nullable String query, int size) {
int maxPageSize = 500;
checkArgument(size <= maxPageSize, "Page size must be lower than or equals to " + maxPageSize);
if (size <= 0) {
return emptyList();
}
TermsAggregationBuilder termsAggregation = AggregationBuilders.terms(AGGREGATION_NAME_FOR_TAGS).field(FIELD_RULE_TAGS).size(size).order(BucketOrder.key(true)).minDocCount(1);
ofNullable(query).map(EsUtils::escapeSpecialRegexChars).map(queryString -> ".*" + queryString + ".*").map(s -> new IncludeExclude(s, null)).ifPresent(termsAggregation::includeExclude);
SearchRequest request = EsClient.prepareSearch(TYPE_RULE.getMainType()).source(new SearchSourceBuilder().query(matchAllQuery()).size(0).aggregation(termsAggregation));
SearchResponse esResponse = client.search(request);
return EsUtils.termsKeys(esResponse.getAggregations().get(AGGREGATION_NAME_FOR_TAGS));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder in project sonarqube by SonarSource.
the class BulkIndexerTest method bulk_delete.
@Test
public void bulk_delete() {
int max = 500;
int removeFrom = 200;
FakeDoc[] docs = new FakeDoc[max];
for (int i = 0; i < max; i++) {
docs[i] = FakeIndexDefinition.newDoc(i);
}
es.putDocuments(TYPE_FAKE, docs);
assertThat(count()).isEqualTo(max);
SearchRequest req = EsClient.prepareSearch(TYPE_FAKE).source(new SearchSourceBuilder().query(QueryBuilders.rangeQuery(FakeIndexDefinition.INT_FIELD).gte(removeFrom)));
BulkIndexer.delete(es.client(), TYPE_FAKE, req);
assertThat(count()).isEqualTo(removeFrom);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder in project sonarqube by SonarSource.
the class UserIndex method search.
public SearchResult<UserDoc> search(UserQuery userQuery, SearchOptions options) {
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(options.getLimit()).from(options.getOffset()).sort(FIELD_NAME, SortOrder.ASC);
BoolQueryBuilder filter = boolQuery().must(termQuery(FIELD_ACTIVE, true));
QueryBuilder esQuery = matchAllQuery();
Optional<String> textQuery = userQuery.getTextQuery();
if (textQuery.isPresent()) {
esQuery = QueryBuilders.multiMatchQuery(textQuery.get(), FIELD_LOGIN, USER_SEARCH_GRAMS_ANALYZER.subField(FIELD_LOGIN), FIELD_NAME, USER_SEARCH_GRAMS_ANALYZER.subField(FIELD_NAME), FIELD_EMAIL, USER_SEARCH_GRAMS_ANALYZER.subField(FIELD_EMAIL)).operator(Operator.AND);
}
SearchRequest request = EsClient.prepareSearch(UserIndexDefinition.TYPE_USER).source(searchSourceBuilder.query(boolQuery().must(esQuery).filter(filter)));
return new SearchResult<>(esClient.search(request), UserDoc::new, system2.getDefaultTimeZone().toZoneId());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder in project sonarqube by SonarSource.
the class EsTester method after.
@Override
protected void after() {
if (isCustom) {
// delete non-core indices
String[] existingIndices = getIndicesNames();
Stream.of(existingIndices).filter(i -> !CORE_INDICES_NAMES.contains(i)).forEach(EsTester::deleteIndexIfExists);
}
BulkIndexer.delete(ES_REST_CLIENT, IndexType.main(ALL_INDICES, "dummy"), EsClient.prepareSearch(ALL_INDICES.getName()).source(new SearchSourceBuilder().query(QueryBuilders.matchAllQuery())));
}
Aggregations