use of org.elasticsearch.action.search.SearchRequestBuilder in project sonarqube by SonarSource.
the class ViewIndex method findAllViewUuids.
public List<String> findAllViewUuids() {
SearchRequestBuilder esSearch = esClient.prepareSearch(ViewIndexDefinition.INDEX_TYPE_VIEW).addSort("_doc", SortOrder.ASC).setScroll(TimeValue.timeValueMinutes(SCROLL_TIME_IN_MINUTES)).setFetchSource(false).setSize(100).setQuery(matchAllQuery());
SearchResponse response = esSearch.get();
List<String> result = newArrayList();
while (true) {
List<SearchHit> hits = newArrayList(response.getHits());
for (SearchHit hit : hits) {
result.add(hit.getId());
}
String scrollId = response.getScrollId();
response = esClient.prepareSearchScroll(scrollId).setScroll(TimeValue.timeValueMinutes(SCROLL_TIME_IN_MINUTES)).get();
// Break condition: No hits are returned
if (response.getHits().getHits().length == 0) {
esClient.nativeClient().prepareClearScroll().addScrollId(scrollId).get();
break;
}
}
return result;
}
use of org.elasticsearch.action.search.SearchRequestBuilder in project sonarqube by SonarSource.
the class EsTester method getDocuments.
/**
* Get all the indexed documents (no paginated results). Results are not sorted.
*/
public List<SearchHit> getDocuments(IndexType indexType) {
SearchRequestBuilder req = client.nativeClient().prepareSearch(indexType.getIndex()).setTypes(indexType.getType()).setQuery(QueryBuilders.matchAllQuery());
req.setSearchType(SearchType.SCAN).setScroll(new TimeValue(60000)).setSize(100);
SearchResponse response = req.get();
List<SearchHit> result = newArrayList();
while (true) {
Iterables.addAll(result, response.getHits());
response = client.nativeClient().prepareSearchScroll(response.getScrollId()).setScroll(new TimeValue(600000)).execute().actionGet();
// Break condition: No hits are returned
if (response.getHits().getHits().length == 0) {
break;
}
}
return result;
}
use of org.elasticsearch.action.search.SearchRequestBuilder in project sonarqube by SonarSource.
the class SortingTest method ascending_sort_on_single_field_with_missing_in_last_position.
@Test
public void ascending_sort_on_single_field_with_missing_in_last_position() throws Exception {
Sorting sorting = new Sorting();
sorting.add("updatedAt").missingLast();
SearchRequestBuilder request = new SearchRequestBuilder(mock(Client.class), SearchAction.INSTANCE);
sorting.fill(request, "updatedAt", true);
List<SortBuilder> fields = fields(request);
assertThat(fields).hasSize(1);
expectField(fields.get(0), "updatedAt", "_last", SortOrder.ASC);
}
use of org.elasticsearch.action.search.SearchRequestBuilder in project sonarqube by SonarSource.
the class SortingTest method default_sorting.
@Test
public void default_sorting() throws Exception {
Sorting sorting = new Sorting();
sorting.addDefault("file");
SearchRequestBuilder request = new SearchRequestBuilder(mock(Client.class), SearchAction.INSTANCE);
sorting.fillDefault(request);
List<SortBuilder> fields = fields(request);
assertThat(fields).hasSize(1);
}
use of org.elasticsearch.action.search.SearchRequestBuilder in project sonarqube by SonarSource.
the class SortingTest method ascending_sort_on_single_field.
@Test
public void ascending_sort_on_single_field() throws Exception {
Sorting sorting = new Sorting();
sorting.add("updatedAt");
SearchRequestBuilder request = new SearchRequestBuilder(mock(Client.class), SearchAction.INSTANCE);
sorting.fill(request, "updatedAt", true);
List<SortBuilder> fields = fields(request);
assertThat(fields).hasSize(1);
expectField(fields.get(0), "updatedAt", "_first", SortOrder.ASC);
}
Aggregations