use of org.elasticsearch.action.search.SearchRequest in project sonarqube by SonarSource.
the class EsRequestDetailsTest method should_format_SearchRequest.
@Test
public void should_format_SearchRequest() {
SearchRequest searchRequest = Requests.searchRequest("index").types("type");
assertThat(EsRequestDetails.computeDetailsAsString(searchRequest)).isEqualTo("ES search request 'SearchRequest{searchType=QUERY_THEN_FETCH, indices=[index]," + " indicesOptions=IndicesOptions[ignore_unavailable=false, allow_no_indices=true," + " expand_wildcards_open=true, expand_wildcards_closed=false, expand_wildcards_hidden=false," + " allow_aliases_to_multiple_indices=true, forbid_closed_indices=true, ignore_aliases=false," + " ignore_throttled=true], types=[type], routing='null', preference='null', requestCache=null," + " scroll=null, maxConcurrentShardRequests=0, batchedReduceSize=512, preFilterShardSize=null," + " allowPartialSearchResults=null, localClusterAlias=null, getOrCreateAbsoluteStartMillis=-1," + " ccsMinimizeRoundtrips=true, enableFieldsEmulation=false, source={}}' on indices '[index]' on types '[type]'");
}
use of org.elasticsearch.action.search.SearchRequest 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.elasticsearch.action.search.SearchRequest 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.elasticsearch.action.search.SearchRequest in project sonarqube by SonarSource.
the class IssueIndex method getMinCreatedAt.
private OptionalLong getMinCreatedAt(AllFilters filters) {
String facetNameAndField = CREATED_AT.getFieldName();
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder().size(0);
BoolQueryBuilder esFilter = boolQuery();
filters.stream().filter(Objects::nonNull).forEach(esFilter::must);
if (esFilter.hasClauses()) {
sourceBuilder.query(QueryBuilders.boolQuery().filter(esFilter));
}
sourceBuilder.aggregation(AggregationBuilders.min(facetNameAndField).field(facetNameAndField));
SearchRequest request = EsClient.prepareSearch(TYPE_ISSUE.getMainType()).source(sourceBuilder);
Min minValue = client.search(request).getAggregations().get(facetNameAndField);
double actualValue = minValue.getValue();
if (Double.isInfinite(actualValue)) {
return OptionalLong.empty();
}
return OptionalLong.of((long) actualValue);
}
use of org.elasticsearch.action.search.SearchRequest in project sonarqube by SonarSource.
the class ComponentIndex method search.
public SearchIdResult<String> search(ComponentQuery query, SearchOptions searchOptions) {
SearchSourceBuilder source = new SearchSourceBuilder().fetchSource(false).trackTotalHits(true).from(searchOptions.getOffset()).size(searchOptions.getLimit());
BoolQueryBuilder esQuery = boolQuery();
esQuery.filter(authorizationTypeSupport.createQueryFilter());
setNullable(query.getQuery(), q -> {
ComponentTextSearchQuery componentTextSearchQuery = ComponentTextSearchQuery.builder().setQueryText(q).setFieldKey(FIELD_KEY).setFieldName(FIELD_NAME).build();
esQuery.must(ComponentTextSearchQueryFactory.createQuery(componentTextSearchQuery, ComponentTextSearchFeatureRepertoire.values()));
});
setEmptiable(query.getQualifiers(), q -> esQuery.must(termsQuery(FIELD_QUALIFIER, q)));
source.sort(SORTABLE_ANALYZER.subField(FIELD_NAME), SortOrder.ASC);
source.query(esQuery);
SearchRequest request = EsClient.prepareSearch(TYPE_COMPONENT.getMainType()).source(source);
return new SearchIdResult<>(client.search(request), id -> id, system2.getDefaultTimeZone().toZoneId());
}
Aggregations