use of org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder 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 org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder 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 org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder in project tutorials by eugenp.
the class ElasticSearchQueryIntegrationTest method givenNotExactPhrase_whenUseSlop_thenQueryMatches.
@Test
public void givenNotExactPhrase_whenUseSlop_thenQueryMatches() {
final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchPhraseQuery("title", "spring elasticsearch").slop(1)).build();
final List<Article> articles = elasticsearchTemplate.queryForList(searchQuery, Article.class);
assertEquals(1, articles.size());
}
use of org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder in project xm-ms-entity by xm-online.
the class PermittedSearchRepository method buildQuery.
private SearchQuery buildQuery(String query, Pageable pageable, String privilegeKey) {
String permittedQuery = buildPermittedQuery(query, privilegeKey);
log.debug("Executing DSL '{}'", permittedQuery);
return new NativeSearchQueryBuilder().withQuery(queryStringQuery(permittedQuery)).withPageable(pageable).build();
}
use of org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder in project tutorials by eugenp.
the class ElasticSearchIntegrationTest method givenSavedDoc_whenTitleUpdated_thenCouldFindByUpdatedTitle.
@Test
public void givenSavedDoc_whenTitleUpdated_thenCouldFindByUpdatedTitle() {
final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(fuzzyQuery("title", "serch")).build();
final List<Article> articles = elasticsearchTemplate.queryForList(searchQuery, Article.class);
assertEquals(1, articles.size());
final Article article = articles.get(0);
final String newTitle = "Getting started with Search Engines";
article.setTitle(newTitle);
articleService.save(article);
assertEquals(newTitle, articleService.findOne(article.getId()).getTitle());
}
Aggregations