use of org.molgenis.data.elasticsearch.client.model.SearchHit in project molgenis by molgenis.
the class ElasticsearchServiceTest method testBatchingSearchPageSizeZero.
@Test
@SuppressWarnings("unchecked")
public void testBatchingSearchPageSizeZero() {
QueryImpl<Entity> query = mock(QueryImpl.class);
when(query.getPageSize()).thenReturn(0);
when(query.getOffset()).thenReturn(0);
SearchHits searchHitsBatch = mock(SearchHits.class);
when(searchHitsBatch.getHits()).thenReturn(asList(new SearchHit[10000]));
SearchHits finalSearchHitsBatch = mock(SearchHits.class);
when(finalSearchHitsBatch.getHits()).thenReturn(asList(new SearchHit[5000]));
when(clientFacade.search(any(), eq(0), eq(10000), any(), any())).thenReturn(searchHitsBatch);
when(clientFacade.search(any(), eq(10000), anyInt(), any(), any())).thenReturn(searchHitsBatch);
when(clientFacade.search(any(), eq(20000), anyInt(), any(), any())).thenReturn(finalSearchHitsBatch);
elasticsearchService.search(entityType, query);
verify(clientFacade, times(1)).search(any(), eq(0), eq(MAX_BATCH_SIZE), any(), any());
verify(clientFacade, times(1)).search(any(), eq(10000), eq(MAX_BATCH_SIZE), any(), any());
verify(clientFacade, times(1)).search(any(), eq(20000), eq(MAX_BATCH_SIZE), any(), any());
verifyNoMoreInteractions(clientFacade);
}
use of org.molgenis.data.elasticsearch.client.model.SearchHit in project molgenis by molgenis.
the class ElasticsearchServiceTest method testBatchingSearchPageSizeLargerThanMax.
@Test
@SuppressWarnings("unchecked")
public void testBatchingSearchPageSizeLargerThanMax() {
QueryImpl<Entity> query = mock(QueryImpl.class);
when(query.getPageSize()).thenReturn(10001);
when(query.getOffset()).thenReturn(5000);
SearchHits searchHitsBatch = mock(SearchHits.class);
when(searchHitsBatch.getHits()).thenReturn(asList(new SearchHit[10000]));
SearchHits finalSearchHitsBatch = mock(SearchHits.class);
when(finalSearchHitsBatch.getHits()).thenReturn(asList(new SearchHit[1]));
when(clientFacade.search(any(), eq(5000), eq(MAX_BATCH_SIZE), any(), any())).thenReturn(searchHitsBatch);
when(clientFacade.search(any(), eq(15000), eq(1), any(), any())).thenReturn(finalSearchHitsBatch);
elasticsearchService.search(entityType, query);
verify(clientFacade, times(1)).search(any(), eq(5000), eq(MAX_BATCH_SIZE), any(), any());
verify(clientFacade, times(1)).search(any(), eq(15000), eq(1), any(), any());
verifyNoMoreInteractions(clientFacade);
}
use of org.molgenis.data.elasticsearch.client.model.SearchHit in project molgenis by molgenis.
the class ElasticsearchServiceTest method testSingleBatchSearch.
@Test
@SuppressWarnings("unchecked")
public void testSingleBatchSearch() {
QueryImpl<Entity> query = mock(QueryImpl.class);
when(query.getPageSize()).thenReturn(50);
when(query.getOffset()).thenReturn(20);
SearchHits searchHitsBatch = mock(SearchHits.class);
when(searchHitsBatch.getHits()).thenReturn(asList(new SearchHit[50]));
when(clientFacade.search(any(), eq(20), eq(50), any(), any())).thenReturn(searchHitsBatch);
elasticsearchService.search(entityType, query);
verify(clientFacade, times(1)).search(any(), eq(20), eq(50), any(), any());
verifyNoMoreInteractions(clientFacade);
}
use of org.molgenis.data.elasticsearch.client.model.SearchHit in project molgenis by molgenis.
the class ElasticsearchService method search.
private Stream<Object> search(EntityType entityType, Query<Entity> q, int offset, int pageSize) {
QueryBuilder query = contentGenerators.createQuery(q, entityType);
Sort sort = q.getSort() != null ? contentGenerators.createSorts(q.getSort(), entityType) : null;
Index index = contentGenerators.createIndex(entityType);
Stream<SearchHit> searchHits = Stream.empty();
boolean done = false;
int currentOffset;
int i = 0;
while (!done) {
int batchSize = pageSize < MAX_BATCH_SIZE && pageSize != 0 ? pageSize : MAX_BATCH_SIZE;
currentOffset = offset + (i * MAX_BATCH_SIZE);
SearchHits currentSearchHits = clientFacade.search(query, currentOffset, batchSize, sort, index);
searchHits = Streams.concat(searchHits, currentSearchHits.getHits().stream());
if (currentSearchHits.getHits().size() < MAX_BATCH_SIZE) {
done = true;
}
if (pageSize != 0)
pageSize -= MAX_BATCH_SIZE;
i++;
}
return toEntityIds(entityType, searchHits.map(SearchHit::getId));
}
use of org.molgenis.data.elasticsearch.client.model.SearchHit in project molgenis by molgenis.
the class ClientFacadeTest method testExplainThrowsException.
@Test(expectedExceptions = IndexException.class, expectedExceptionsMessageRegExp = "Error explaining doc with id 'id' in index 'index' for query 'a == b'\\.")
public void testExplainThrowsException() {
SearchHit searchHit = SearchHit.create("id", "index");
when(client.prepareExplain("index", "index", "id")).thenReturn(explainRequestBuilder);
when(explainRequestBuilder.setQuery(any())).thenReturn(explainRequestBuilder);
when(explainRequestBuilder.get()).thenThrow(new ElasticsearchException("exception"));
when(queryBuilder.toString()).thenReturn("a == b");
clientFacade.explain(searchHit, queryBuilder);
}
Aggregations