Package org.springframework.data.elasticsearch.core.query

Examples of org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder


  @Test
  public void shouldReturnFacetedAuthorsForGivenQueryOrderedByTerm() {

    // given
    String facetName = "fauthors";
    SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
        .withFacet(new TermFacetRequestBuilder(facetName).fields("authors.untouched").ascTerm().build()).build();
    // when
    FacetedPage<ArticleEntity> result = elasticsearchTemplate.queryForPage(searchQuery, ArticleEntity.class);
    // then
    assertThat(result.getNumberOfElements(), is(equalTo(4)));
View Full Code Here


  @Test
  public void shouldReturnFacetedAuthorsForGivenQueryOrderedByCountAsc() {

    // given
    String facetName = "fauthors";
    SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
        .withFacet(new TermFacetRequestBuilder(facetName).fields("authors.untouched").ascCount().build()).build();
    // when
    FacetedPage<ArticleEntity> result = elasticsearchTemplate.queryForPage(searchQuery, ArticleEntity.class);
    // then
    assertThat(result.getNumberOfElements(), is(equalTo(4)));
View Full Code Here

  @Test
  public void shouldReturnFacetedYearsForGivenQuery() {

    // given
    String facetName = "fyears";
    SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
        .withFacet(new TermFacetRequestBuilder(facetName).fields("publishedYears").descCount().build()).build();
    // when
    FacetedPage<ArticleEntity> result = elasticsearchTemplate.queryForPage(searchQuery, ArticleEntity.class);
    // then
    assertThat(result.getNumberOfElements(), is(equalTo(4)));
View Full Code Here

  @Test
  public void shouldReturnSingleFacetOverYearsAndAuthorsForGivenQuery() {

    // given
    String facetName = "fyears";
    SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
        .withFacet(new TermFacetRequestBuilder(facetName).fields("publishedYears", "authors.untouched").ascTerm().build()).build();
    // when
    FacetedPage<ArticleEntity> result = elasticsearchTemplate.queryForPage(searchQuery, ArticleEntity.class);
    // then
    assertThat(result.getNumberOfElements(), is(equalTo(4)));
View Full Code Here

  public void shouldReturnFacetedYearsAndFacetedAuthorsForGivenQuery() {

    // given
    String numberFacetName = "fAuthors";
    String stringFacetName = "fyears";
    SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
        .withFacet(new TermFacetRequestBuilder(numberFacetName).fields("publishedYears").ascTerm().build())
        .withFacet(new TermFacetRequestBuilder(stringFacetName).fields("authors.untouched").ascTerm().build())
        .build();
    // when
    FacetedPage<ArticleEntity> result = elasticsearchTemplate.queryForPage(searchQuery, ArticleEntity.class);
View Full Code Here

  @Test
  public void shouldReturnFacetedYearsForNativeFacet() {

    // given
    String facetName = "fyears";
    SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
        .withFacet(new NativeFacetRequest(FacetBuilders.termsFacet(facetName).field("publishedYears"))).build();
    // when
    FacetedPage<ArticleEntity> result = elasticsearchTemplate.queryForPage(searchQuery, ArticleEntity.class);
    // then
    assertThat(result.getNumberOfElements(), is(equalTo(4)));
View Full Code Here

  @Test
  public void shouldFilterResultByRegexForGivenQuery() {
    // given
    String facetName = "regex_authors";
    SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
        .withFilter(FilterBuilders.notFilter(FilterBuilders.termFilter("title", "four")))
        .withFacet(new TermFacetRequestBuilder(facetName).applyQueryFilter().fields("authors.untouched").regex("Art.*").build()).build();
    // when
    FacetedPage<ArticleEntity> result = elasticsearchTemplate.queryForPage(searchQuery, ArticleEntity.class);
    // then
View Full Code Here

  @Test
  public void shouldReturnAllTermsForGivenQuery() {
    // given
    String facetName = "all_authors";
    SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
        .withFilter(FilterBuilders.notFilter(FilterBuilders.termFilter("title", "four")))
        .withFacet(new TermFacetRequestBuilder(facetName).applyQueryFilter().fields("authors.untouched").allTerms().build()).build();
    // when
    FacetedPage<ArticleEntity> result = elasticsearchTemplate.queryForPage(searchQuery, ArticleEntity.class);
    // then
View Full Code Here

  @Test
  public void shouldReturnRangeFacetForGivenQuery() {
    // given
    String facetName = "rangeYears";
    SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
        .withFacet(
            new RangeFacetRequestBuilder(facetName).field(PUBLISHED_YEARS)
                .to(YEAR_2000).range(YEAR_2000, YEAR_2002).from(YEAR_2002).build()
        ).build();
    // when
View Full Code Here

  @Test
  public void shouldReturnKeyValueRangeFacetForGivenQuery() {
    // given
    String facetName = "rangeScoreOverYears";
    SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
        .withFacet(
            new RangeFacetRequestBuilder(facetName).fields(PUBLISHED_YEARS, "score")
                .to(YEAR_2000).range(YEAR_2000, YEAR_2002).from(YEAR_2002).build()
        ).build();
    // when
View Full Code Here

TOP

Related Classes of org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.