use of com.baeldung.spring.data.es.model.Article in project tutorials by eugenp.
the class ElasticSearchQueryIntegrationTest method givenPartTitle_whenRunMatchQuery_thenDocIsFound.
@Test
public void givenPartTitle_whenRunMatchQuery_thenDocIsFound() {
final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title", "elasticsearch data")).build();
final List<Article> articles = elasticsearchTemplate.queryForList(searchQuery, Article.class);
assertEquals(3, articles.size());
}
use of com.baeldung.spring.data.es.model.Article in project tutorials by eugenp.
the class ElasticSearchQueryIntegrationTest method givenFullTitle_whenRunMatchQuery_thenDocIsFound.
@Test
public void givenFullTitle_whenRunMatchQuery_thenDocIsFound() {
final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title", "Search engines").operator(AND)).build();
final List<Article> articles = elasticsearchTemplate.queryForList(searchQuery, Article.class);
assertEquals(1, articles.size());
}
use of com.baeldung.spring.data.es.model.Article in project tutorials by eugenp.
the class ElasticSearchQueryIntegrationTest method givenOneTermFromTitle_whenRunMatchQuery_thenDocIsFound.
@Test
public void givenOneTermFromTitle_whenRunMatchQuery_thenDocIsFound() {
final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title", "Engines Solutions")).build();
final List<Article> articles = elasticsearchTemplate.queryForList(searchQuery, Article.class);
assertEquals(1, articles.size());
assertEquals("Search engines", articles.get(0).getTitle());
}
use of com.baeldung.spring.data.es.model.Article in project tutorials by eugenp.
the class ElasticSearchQueryIntegrationTest method givenNestedObject_whenQueryByAuthorsName_thenFoundArticlesByThatAuthor.
@Test
public void givenNestedObject_whenQueryByAuthorsName_thenFoundArticlesByThatAuthor() {
final QueryBuilder builder = nestedQuery("authors", boolQuery().must(termQuery("authors.name", "smith")));
final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder).build();
final List<Article> articles = elasticsearchTemplate.queryForList(searchQuery, Article.class);
assertEquals(2, articles.size());
}
use of com.baeldung.spring.data.es.model.Article in project tutorials by eugenp.
the class ElasticSearchQueryIntegrationTest method before.
@Before
public void before() {
elasticsearchTemplate.deleteIndex(Article.class);
elasticsearchTemplate.createIndex(Article.class);
elasticsearchTemplate.putMapping(Article.class);
elasticsearchTemplate.refresh(Article.class);
Article article = new Article("Spring Data Elasticsearch");
article.setAuthors(asList(johnSmith, johnDoe));
article.setTags("elasticsearch", "spring data");
articleService.save(article);
article = new Article("Search engines");
article.setAuthors(asList(johnDoe));
article.setTags("search engines", "tutorial");
articleService.save(article);
article = new Article("Second Article About Elasticsearch");
article.setAuthors(asList(johnSmith));
article.setTags("elasticsearch", "spring data");
articleService.save(article);
article = new Article("Elasticsearch Tutorial");
article.setAuthors(asList(johnDoe));
article.setTags("elasticsearch");
articleService.save(article);
}
Aggregations