use of org.elasticsearch.action.search.SearchRequestBuilder in project sonarqube by SonarSource.
the class UserIndex method search.
public SearchResult<UserDoc> search(@Nullable String searchText, SearchOptions options) {
SearchRequestBuilder request = esClient.prepareSearch(UserIndexDefinition.INDEX_TYPE_USER).setSize(options.getLimit()).setFrom(options.getOffset()).addSort(FIELD_NAME, SortOrder.ASC);
BoolQueryBuilder filter = boolQuery().must(termQuery(FIELD_ACTIVE, true));
QueryBuilder query;
if (StringUtils.isEmpty(searchText)) {
query = matchAllQuery();
} else {
query = QueryBuilders.multiMatchQuery(searchText, 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(MatchQueryBuilder.Operator.AND);
}
request.setQuery(boolQuery().must(query).filter(filter));
return new SearchResult<>(request.get(), DOC_CONVERTER);
}
use of org.elasticsearch.action.search.SearchRequestBuilder in project sonarqube by SonarSource.
the class UserIndex method selectUsersForBatch.
public Iterator<UserDoc> selectUsersForBatch(List<String> logins) {
BoolQueryBuilder filter = boolQuery().filter(termsQuery(FIELD_LOGIN, logins));
SearchRequestBuilder requestBuilder = esClient.prepareSearch(UserIndexDefinition.INDEX_TYPE_USER).setSearchType(SearchType.SCAN).addSort(SortBuilders.fieldSort(FIELD_LOGIN).order(SortOrder.ASC)).setScroll(TimeValue.timeValueMinutes(EsUtils.SCROLL_TIME_IN_MINUTES)).setSize(10_000).setFetchSource(new String[] { FIELD_LOGIN, FIELD_NAME }, null).setQuery(filter);
SearchResponse response = requestBuilder.get();
return EsUtils.scroll(esClient, response.getScrollId(), DOC_CONVERTER);
}
use of org.elasticsearch.action.search.SearchRequestBuilder in project sonarqube by SonarSource.
the class TestIndexer method deleteByFile.
public void deleteByFile(String fileUuid) {
SearchRequestBuilder searchRequest = esClient.prepareSearch(INDEX_TYPE_TEST).setQuery(QueryBuilders.termsQuery(FIELD_FILE_UUID, fileUuid));
BulkIndexer.delete(esClient, INDEX_TYPE_TEST.getIndex(), searchRequest);
}
use of org.elasticsearch.action.search.SearchRequestBuilder in project sonarqube by SonarSource.
the class ViewIndex method delete.
public void delete(Collection<String> viewUuids) {
SearchRequestBuilder searchRequest = esClient.prepareSearch(ViewIndexDefinition.INDEX_TYPE_VIEW).setQuery(boolQuery().must(matchAllQuery()).filter(termsQuery(ViewIndexDefinition.FIELD_UUID, viewUuids)));
BulkIndexer.delete(esClient, ViewIndexDefinition.INDEX_TYPE_VIEW.getIndex(), searchRequest);
}
use of org.elasticsearch.action.search.SearchRequestBuilder in project sonarqube by SonarSource.
the class SortingTest method fail_if_unknown_field.
@Test
public void fail_if_unknown_field() {
Sorting sorting = new Sorting();
sorting.add("file");
try {
sorting.fill(new SearchRequestBuilder(mock(Client.class), SearchAction.INSTANCE), "unknown", true);
fail();
} catch (BadRequestException e) {
assertThat(e.getMessage()).isEqualTo("Bad sort field: unknown");
}
}
Aggregations