Search in sources :

Example 11 with IndexCoordinates

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();
}
Also used : IndexQuery(org.springframework.data.elasticsearch.core.query.IndexQuery) ArrayList(java.util.ArrayList) IndexCoordinates(org.springframework.data.elasticsearch.core.mapping.IndexCoordinates)

Example 12 with IndexCoordinates

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);
}
Also used : IndexCoordinates(org.springframework.data.elasticsearch.core.mapping.IndexCoordinates) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 13 with IndexCoordinates

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");
}
Also used : Query(org.springframework.data.elasticsearch.core.query.Query) IndexQuery(org.springframework.data.elasticsearch.core.query.IndexQuery) NativeSearchQuery(org.springframework.data.elasticsearch.core.query.NativeSearchQuery) NativeSearchQuery(org.springframework.data.elasticsearch.core.query.NativeSearchQuery) IndexCoordinates(org.springframework.data.elasticsearch.core.mapping.IndexCoordinates) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 14 with IndexCoordinates

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");
}
Also used : Query(org.springframework.data.elasticsearch.core.query.Query) IndexQuery(org.springframework.data.elasticsearch.core.query.IndexQuery) NativeSearchQuery(org.springframework.data.elasticsearch.core.query.NativeSearchQuery) NativeSearchQuery(org.springframework.data.elasticsearch.core.query.NativeSearchQuery) IndexCoordinates(org.springframework.data.elasticsearch.core.mapping.IndexCoordinates) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 15 with IndexCoordinates

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");
}
Also used : Query(org.springframework.data.elasticsearch.core.query.Query) IndexQuery(org.springframework.data.elasticsearch.core.query.IndexQuery) NativeSearchQuery(org.springframework.data.elasticsearch.core.query.NativeSearchQuery) NativeSearchQuery(org.springframework.data.elasticsearch.core.query.NativeSearchQuery) IndexCoordinates(org.springframework.data.elasticsearch.core.mapping.IndexCoordinates) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Aggregations

IndexCoordinates (org.springframework.data.elasticsearch.core.mapping.IndexCoordinates)50 Test (org.junit.jupiter.api.Test)27 SpringIntegrationTest (org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)27 IndexQuery (org.springframework.data.elasticsearch.core.query.IndexQuery)20 NativeSearchQueryBuilder (org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder)16 Query (org.springframework.data.elasticsearch.core.query.Query)16 ArrayList (java.util.ArrayList)15 Nullable (org.springframework.lang.Nullable)11 HashMap (java.util.HashMap)10 List (java.util.List)10 Collectors (java.util.stream.Collectors)10 QueryBuilders (org.elasticsearch.index.query.QueryBuilders)10 Map (java.util.Map)9 SearchRequest (org.elasticsearch.action.search.SearchRequest)9 UpdateRequest (org.elasticsearch.action.update.UpdateRequest)9 Log (org.apache.commons.logging.Log)8 LogFactory (org.apache.commons.logging.LogFactory)8 Version (org.elasticsearch.Version)8 DocWriteResponse (org.elasticsearch.action.DocWriteResponse)8 BulkItemResponse (org.elasticsearch.action.bulk.BulkItemResponse)8