use of org.springframework.data.elasticsearch.core.mapping.IndexCoordinates in project spring-data-elasticsearch by spring-projects.
the class SearchAsYouTypeTests method loadEntities.
private void loadEntities() {
List<IndexQuery> indexQueries = new ArrayList<>();
indexQueries.add(new SearchAsYouTypeEntity("1", "test 1", "test 1234").toIndex());
indexQueries.add(new SearchAsYouTypeEntity("2", "test 2", "test 5678").toIndex());
indexQueries.add(new SearchAsYouTypeEntity("3", "test 3", "asd 5678").toIndex());
indexQueries.add(new SearchAsYouTypeEntity("4", "test 4", "not match").toIndex());
IndexCoordinates index = IndexCoordinates.of("test-index-core-search-as-you-type");
operations.bulkIndex(indexQueries, index);
operations.indexOps(SearchAsYouTypeEntity.class).refresh();
}
use of org.springframework.data.elasticsearch.core.mapping.IndexCoordinates in project spring-data-elasticsearch by spring-projects.
the class SearchAsYouTypeTests method shouldRetrieveEntityById.
// DATAES-773
@Test
void shouldRetrieveEntityById() {
loadEntities();
IndexCoordinates index = IndexCoordinates.of("test-index-core-search-as-you-type");
operations.get("1", SearchAsYouTypeEntity.class, index);
}
use of org.springframework.data.elasticsearch.core.mapping.IndexCoordinates in project spring-data-elasticsearch by spring-projects.
the class SearchAsYouTypeTests method shouldReturnCorrectResultsForTextString.
// DATAES-773
@Test
void shouldReturnCorrectResultsForTextString() {
// given
loadEntities();
// when
Query query = new NativeSearchQuery(//
QueryBuilders.multiMatchQuery(//
"test ", "suggest", "suggest._2gram", "suggest._3gram", "suggest._4gram").type(MultiMatchQueryBuilder.Type.BOOL_PREFIX));
IndexCoordinates index = IndexCoordinates.of("test-index-core-search-as-you-type");
List<SearchAsYouTypeEntity> result = //
operations.search(query, SearchAsYouTypeEntity.class, index).getSearchHits().stream().map(//
SearchHit::getContent).collect(Collectors.toList());
// then
List<String> ids = result.stream().map(SearchAsYouTypeEntity::getId).collect(Collectors.toList());
assertThat(ids).containsExactlyInAnyOrder("1", "2");
}
use of org.springframework.data.elasticsearch.core.mapping.IndexCoordinates in project spring-data-elasticsearch by spring-projects.
the class SearchAsYouTypeTests method shouldReturnCorrectResultsForNumQuery.
// DATAES-773
@Test
void shouldReturnCorrectResultsForNumQuery() {
// given
loadEntities();
// when
Query query = new NativeSearchQuery(//
QueryBuilders.multiMatchQuery(//
"5678 ", "suggest", "suggest._2gram", "suggest._3gram", "suggest._4gram").type(MultiMatchQueryBuilder.Type.BOOL_PREFIX));
IndexCoordinates index = IndexCoordinates.of("test-index-core-search-as-you-type");
List<SearchAsYouTypeEntity> result = //
operations.search(query, SearchAsYouTypeEntity.class, index).getSearchHits().stream().map(//
SearchHit::getContent).collect(Collectors.toList());
// then
List<String> ids = result.stream().map(SearchAsYouTypeEntity::getId).collect(Collectors.toList());
assertThat(ids).containsExactlyInAnyOrder("2", "3");
}
use of org.springframework.data.elasticsearch.core.mapping.IndexCoordinates in project spring-data-elasticsearch by spring-projects.
the class SearchAsYouTypeTests method shouldReturnCorrectResultsForNotMatchQuery.
// DATAES-773
@Test
void shouldReturnCorrectResultsForNotMatchQuery() {
// given
loadEntities();
// when
Query query = new NativeSearchQuery(//
QueryBuilders.multiMatchQuery(//
"n mat", "suggest", "suggest._2gram", "suggest._3gram", "suggest._4gram").type(MultiMatchQueryBuilder.Type.BOOL_PREFIX));
IndexCoordinates index = IndexCoordinates.of("test-index-core-search-as-you-type");
List<SearchAsYouTypeEntity> result = //
operations.search(query, SearchAsYouTypeEntity.class, index).getSearchHits().stream().map(//
SearchHit::getContent).collect(Collectors.toList());
// then
assertThat(result.get(0).getId()).isEqualTo("4");
}
Aggregations