Search in sources :

Example 11 with SearchQuery

use of org.springframework.data.elasticsearch.core.query.SearchQuery 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 12 with SearchQuery

use of org.springframework.data.elasticsearch.core.query.SearchQuery 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 13 with SearchQuery

use of org.springframework.data.elasticsearch.core.query.SearchQuery 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)13 Test (org.junit.Test)13 NativeSearchQueryBuilder (org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder)13 SearchQuery (org.springframework.data.elasticsearch.core.query.SearchQuery)13 MultiMatchQueryBuilder (org.elasticsearch.index.query.MultiMatchQueryBuilder)2 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)2