use of org.elasticsearch.action.search.SearchRequestBuilder in project sonarqube by SonarSource.
the class SortingTest method descending_sort_on_single_field.
@Test
public void descending_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", false);
List<SortBuilder> fields = fields(request);
assertThat(fields).hasSize(1);
expectField(fields.get(0), "updatedAt", "_last", SortOrder.DESC);
}
use of org.elasticsearch.action.search.SearchRequestBuilder in project sonarqube by SonarSource.
the class SortingTest method descending_sort_on_single_field_with_missing_in_last_position.
@Test
public void descending_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", false);
List<SortBuilder> fields = fields(request);
assertThat(fields).hasSize(1);
expectField(fields.get(0), "updatedAt", "_first", SortOrder.DESC);
}
use of org.elasticsearch.action.search.SearchRequestBuilder in project sonarqube by SonarSource.
the class BulkIndexerTest method bulk_delete.
@Test
public void bulk_delete() throws Exception {
int max = 500;
int removeFrom = 200;
FakeDoc[] docs = new FakeDoc[max];
for (int i = 0; i < max; i++) {
docs[i] = FakeIndexDefinition.newDoc(i);
}
esTester.putDocuments(INDEX_TYPE_FAKE, docs);
assertThat(count()).isEqualTo(max);
SearchRequestBuilder req = esTester.client().prepareSearch(INDEX_TYPE_FAKE).setQuery(QueryBuilders.rangeQuery(FakeIndexDefinition.INT_FIELD).gte(removeFrom));
BulkIndexer.delete(esTester.client(), INDEX, req);
assertThat(count()).isEqualTo(removeFrom);
}
use of org.elasticsearch.action.search.SearchRequestBuilder in project sonarqube by SonarSource.
the class ProjectMeasuresIndexerTest method update_existing_document_when_indexing_one_project.
@Test
public void update_existing_document_when_indexing_one_project() throws Exception {
String uuid = "PROJECT-UUID";
esTester.putDocuments(INDEX_TYPE_PROJECT_MEASURES, new ProjectMeasuresDoc().setId(uuid).setKey("Old Key").setName("Old Name").setTags(singletonList("old tag")).setAnalysedAt(new Date(1_000_000L)));
ComponentDto project = newProjectDto(dbTester.getDefaultOrganization(), uuid).setKey("New key").setName("New name").setTagsString("new tag");
SnapshotDto analysis = componentDbTester.insertProjectAndSnapshot(project);
underTest.indexProject(project.uuid(), ProjectIndexer.Cause.NEW_ANALYSIS);
assertThat(esTester.getIds(INDEX_TYPE_PROJECT_MEASURES)).containsOnly(uuid);
SearchRequestBuilder request = esTester.client().prepareSearch(INDEX_TYPE_PROJECT_MEASURES).setQuery(boolQuery().must(matchAllQuery()).filter(boolQuery().must(termQuery("_id", uuid)).must(termQuery(FIELD_KEY, "New key")).must(termQuery(FIELD_NAME, "New name")).must(termQuery(FIELD_TAGS, "new tag")).must(termQuery(FIELD_ANALYSED_AT, new Date(analysis.getCreatedAt())))));
assertThat(request.get().getHits()).hasSize(1);
}
use of org.elasticsearch.action.search.SearchRequestBuilder in project wonderdog by infochimps-labs.
the class ElasticSearchStreamingInputFormat method findNumHits.
private void findNumHits() {
SearchRequestBuilder request = client.prepareSearch(indexName);
if (mappingName != null && mappingName.length() > 0) {
request.setTypes(mappingName);
}
request.setSearchType(SearchType.COUNT);
if (queryJSON != null && queryJSON.length() > 0) {
request.setQuery(queryJSON);
}
SearchResponse response = request.execute().actionGet();
this.numHits = response.getHits().totalHits();
LOG.info("Ran query: " + String.valueOf(numHits) + " hits");
}
Aggregations