Search in sources :

Example 16 with Article

use of com.baeldung.spring.data.es.model.Article in project tutorials by eugenp.

the class ElasticSearchIntegrationTest method givenTagFilterQuery_whenSearchByAuthorsName_thenArticleIsFound.

@Test
public void givenTagFilterQuery_whenSearchByAuthorsName_thenArticleIsFound() {
    final Page<Article> articleByAuthorName = articleService.findByAuthorsNameAndFilteredTagQuery("Doe", "elasticsearch", new PageRequest(0, 10));
    assertEquals(2L, articleByAuthorName.getTotalElements());
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Article(com.baeldung.spring.data.es.model.Article) Test(org.junit.Test)

Example 17 with Article

use of com.baeldung.spring.data.es.model.Article in project tutorials by eugenp.

the class ElasticSearchIntegrationTest method givenSavedDoc_whenDelete_thenRemovedFromIndex.

@Test
public void givenSavedDoc_whenDelete_thenRemovedFromIndex() {
    final String articleTitle = "Spring Data Elasticsearch";
    final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title", articleTitle).minimumShouldMatch("75%")).build();
    final List<Article> articles = elasticsearchTemplate.queryForList(searchQuery, Article.class);
    assertEquals(1, articles.size());
    final long count = articleService.count();
    articleService.delete(articles.get(0));
    assertEquals(count - 1, articleService.count());
}
Also used : SearchQuery(org.springframework.data.elasticsearch.core.query.SearchQuery) Article(com.baeldung.spring.data.es.model.Article) NativeSearchQueryBuilder(org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder) Test(org.junit.Test)

Example 18 with Article

use of com.baeldung.spring.data.es.model.Article in project tutorials by eugenp.

the class ElasticSearchIntegrationTest method givenPersistedArticles_whenUseRegexQuery_thenRightArticlesFound.

@Test
public void givenPersistedArticles_whenUseRegexQuery_thenRightArticlesFound() {
    final SearchQuery searchQuery = new NativeSearchQueryBuilder().withFilter(regexpQuery("title", ".*data.*")).build();
    final List<Article> articles = elasticsearchTemplate.queryForList(searchQuery, Article.class);
    assertEquals(1, articles.size());
}
Also used : SearchQuery(org.springframework.data.elasticsearch.core.query.SearchQuery) Article(com.baeldung.spring.data.es.model.Article) NativeSearchQueryBuilder(org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder) Test(org.junit.Test)

Example 19 with Article

use of com.baeldung.spring.data.es.model.Article in project tutorials by eugenp.

the class ElasticSearchQueryIntegrationTest method givenPhraseWithType_whenUseFuzziness_thenQueryMatches.

@Test
public void givenPhraseWithType_whenUseFuzziness_thenQueryMatches() {
    final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title", "spring date elasticserch").operator(AND).fuzziness(Fuzziness.ONE).prefixLength(3)).build();
    final List<Article> articles = elasticsearchTemplate.queryForList(searchQuery, Article.class);
    assertEquals(1, articles.size());
}
Also used : SearchQuery(org.springframework.data.elasticsearch.core.query.SearchQuery) Article(com.baeldung.spring.data.es.model.Article) NativeSearchQueryBuilder(org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder) Test(org.junit.Test)

Example 20 with Article

use of com.baeldung.spring.data.es.model.Article in project tutorials by eugenp.

the class ElasticSearchQueryIntegrationTest method givenFullTitle_whenRunMatchQueryOnVerbatimField_thenDocIsFound.

@Test
public void givenFullTitle_whenRunMatchQueryOnVerbatimField_thenDocIsFound() {
    SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title.verbatim", "Second Article About Elasticsearch")).build();
    List<Article> articles = elasticsearchTemplate.queryForList(searchQuery, Article.class);
    assertEquals(1, articles.size());
    searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title.verbatim", "Second Article About")).build();
    articles = elasticsearchTemplate.queryForList(searchQuery, Article.class);
    assertEquals(0, articles.size());
}
Also used : SearchQuery(org.springframework.data.elasticsearch.core.query.SearchQuery) Article(com.baeldung.spring.data.es.model.Article) NativeSearchQueryBuilder(org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder) Test(org.junit.Test)

Aggregations

Article (com.baeldung.spring.data.es.model.Article)20 Test (org.junit.Test)18 NativeSearchQueryBuilder (org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder)13 SearchQuery (org.springframework.data.elasticsearch.core.query.SearchQuery)13 PageRequest (org.springframework.data.domain.PageRequest)4 MultiMatchQueryBuilder (org.elasticsearch.index.query.MultiMatchQueryBuilder)2 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)2 Before (org.junit.Before)2 Author (com.baeldung.spring.data.es.model.Author)1