use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.SearchHit in project sonarqube by SonarSource.
the class ComponentIndex method bucketToQualifier.
private static ComponentHitsPerQualifier bucketToQualifier(ParsedFilters.ParsedBucket bucket) {
ParsedTopHits docs = bucket.getAggregations().get(DOCS_AGGREGATION_NAME);
SearchHits hitList = docs.getHits();
SearchHit[] hits = hitList.getHits();
return new ComponentHitsPerQualifier(bucket.getKey(), ComponentHit.fromSearchHits(hits), getTotalHits(hitList.getTotalHits()).value);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.SearchHit in project sonarqube by SonarSource.
the class IssueIndexTest method search_nine_issues_with_same_creation_date_sorted_by_creation_date_order_is_sorted_also_by_key.
@Test
public void search_nine_issues_with_same_creation_date_sorted_by_creation_date_order_is_sorted_also_by_key() {
ComponentDto project = newPrivateProjectDto();
ComponentDto file = newFileDto(project, null);
List<IssueDoc> issues = new ArrayList<>();
// we are adding issues in reverse order to see if the sort is actually doing anything
for (int i = 9; i >= 1; i--) {
String key = "I" + i;
issues.add(newDoc(key, file));
}
indexIssues(issues.toArray(new IssueDoc[] {}));
IssueQuery.Builder query = IssueQuery.builder().asc(true);
SearchResponse result = underTest.search(query.sort(IssueQuery.SORT_BY_CREATION_DATE).build(), new SearchOptions());
SearchHit[] hits = result.getHits().getHits();
for (int i = 1; i <= 9; i++) {
assertThat(hits[i - 1].getId()).isEqualTo("I" + i);
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.SearchHit in project sonarqube by SonarSource.
the class BulkIndexer method addDeletion.
public void addDeletion(SearchRequest searchRequest) {
// TODO to be replaced by delete_by_query that is back in ES5
searchRequest.scroll(TimeValue.timeValueMinutes(5)).source().sort("_doc", SortOrder.ASC).size(100).fetchSource(false);
// this search is synchronous. An optimization would be to be non-blocking,
// but it requires to tracking pending requests in close().
// Same semaphore can't be reused because of potential deadlock (requires to acquire
// two locks)
SearchResponse searchResponse = esClient.search(searchRequest);
while (true) {
SearchHit[] hits = searchResponse.getHits().getHits();
for (SearchHit hit : hits) {
DocumentField routing = hit.field("_routing");
DeleteRequest deleteRequest = new DeleteRequest(hit.getIndex(), hit.getType(), hit.getId());
if (routing != null) {
deleteRequest.routing(routing.getValue());
}
add(deleteRequest);
}
String scrollId = searchResponse.getScrollId();
if (scrollId == null) {
break;
}
searchResponse = esClient.scroll(new SearchScrollRequest(scrollId).scroll(TimeValue.timeValueMinutes(5)));
if (hits.length == 0) {
ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
clearScrollRequest.addScrollId(scrollId);
esClient.clearScroll(clearScrollRequest);
break;
}
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.SearchHit in project sonarqube by SonarSource.
the class EsUtilsTest method convertToDocs.
@Test
public void convertToDocs() {
SearchHits hits = new SearchHits(new SearchHit[] { new SearchHit(16) }, new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1);
List<BaseDoc> docs = EsUtils.convertToDocs(hits, IssueDoc::new);
assertThat(docs).hasSize(1);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.SearchHit in project sonarqube by SonarSource.
the class UserUpdaterCreateTest method create_user.
@Test
public void create_user() {
createDefaultGroup();
UserDto dto = underTest.createAndCommit(db.getSession(), NewUser.builder().setLogin("user").setName("User").setEmail("user@mail.com").setPassword("PASSWORD").setScmAccounts(ImmutableList.of("u1", "u_1", "User 1")).build(), u -> {
});
assertThat(dto.getUuid()).isNotNull();
assertThat(dto.getLogin()).isEqualTo("user");
assertThat(dto.getName()).isEqualTo("User");
assertThat(dto.getEmail()).isEqualTo("user@mail.com");
assertThat(dto.getScmAccountsAsList()).containsOnly("u1", "u_1", "User 1");
assertThat(dto.isActive()).isTrue();
assertThat(dto.isLocal()).isTrue();
assertThat(dto.getSalt()).isNotNull();
assertThat(dto.getHashMethod()).isEqualTo(HashMethod.PBKDF2.name());
assertThat(dto.getCryptedPassword()).isNotNull();
assertThat(dto.getCreatedAt()).isPositive().isEqualTo(dto.getUpdatedAt());
assertThat(dbClient.userDao().selectByLogin(session, "user").getUuid()).isEqualTo(dto.getUuid());
List<SearchHit> indexUsers = es.getDocuments(UserIndexDefinition.TYPE_USER);
assertThat(indexUsers).hasSize(1);
assertThat(indexUsers.get(0).getSourceAsMap()).contains(entry("login", "user"), entry("name", "User"), entry("email", "user@mail.com"));
}
Aggregations