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

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


    double price = 2.34;
    String id = "abc";
    elasticsearchTemplate.index(new StockPriceBuilder(id).symbol(symbol).price(price).buildIndex());
    elasticsearchTemplate.refresh(StockPrice.class, true);

    SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
    List<StockPrice> result = elasticsearchTemplate.queryForList(searchQuery, StockPrice.class);
    //Then
    assertThat(result.size(), is(1));
    StockPrice entry = result.get(0);
    assertThat(entry.getSymbol(), is(symbol));
View Full Code Here


    String message = "msg";
    String id = "abc";
    elasticsearchTemplate.index(new SampleInheritedEntityBuilder(id).createdDate(createdDate).message(message).buildIndex());
    elasticsearchTemplate.refresh(SampleInheritedEntity.class, true);

    SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
    List<SampleInheritedEntity> result = elasticsearchTemplate.queryForList(searchQuery, SampleInheritedEntity.class);
    //Then
    assertThat(result.size(), is(1));
    SampleInheritedEntity entry = result.get(0);
    assertThat(entry.getCreatedDate(), is(createdDate));
View Full Code Here

    sampleEntity.setId(documentId);
    sampleEntity.setMessage("some test message");
    sampleEntity.setVersion(System.currentTimeMillis());
    repository.save(sampleEntity);

    SearchQuery query = new NativeSearchQueryBuilder().withQuery(termQuery("message", "test")).build();
    // when
    Page<SampleEntity> page = repository.search(query);
    // then
    assertThat(page, is(notNullValue()));
    assertThat(page.getNumberOfElements(), is(greaterThanOrEqualTo(1)));
View Full Code Here

    sampleEntity.setId(documentId);
    sampleEntity.setMessage("hello world.");
    sampleEntity.setVersion(System.currentTimeMillis());
    repository.save(sampleEntity);
    // when
    SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("id", documentId)).build();
    Page<SampleEntity> sampleEntities = repository.search(searchQuery);
    // then
    assertThat(sampleEntities.getTotalElements(), equalTo(1L));
  }
View Full Code Here

  @Test
  public void shouldDeleteAll() {
    // when
    repository.deleteAll();
    // then
    SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
    Page<SampleEntity> sampleEntities = repository.search(searchQuery);
    assertThat(sampleEntities.getTotalElements(), equalTo(0L));
  }
View Full Code Here

    sampleEntity.setVersion(System.currentTimeMillis());
    repository.save(sampleEntity);
    // when
    repository.delete(sampleEntity);
    // then
    SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("id", documentId)).build();
    Page<SampleEntity> sampleEntities = repository.search(searchQuery);
    assertThat(sampleEntities.getTotalElements(), equalTo(0L));
  }
View Full Code Here

  @Test
  public void shouldReturnFacetedAuthorsForGivenQueryWithDefaultOrder() {

    // given
    String facetName = "fauthors";
    SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withFacet(new TermFacetRequestBuilder(facetName).fields("authors.untouched").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 shouldReturnFacetedAuthorsForGivenFilteredQuery() {

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

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

  @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

TOP

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

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.