Package org.springframework.data.elasticsearch.entities

Examples of org.springframework.data.elasticsearch.entities.SampleEntity


  public void shouldReturnListForGivenCriteria() {
    // given
    List<IndexQuery> indexQueries = new ArrayList<IndexQuery>();
    // first document
    String documentId = randomNumeric(5);
    SampleEntity sampleEntity1 = new SampleEntityBuilder(documentId)
        .message("test message")
        .version(System.currentTimeMillis()).build();

    // second document
    String documentId2 = randomNumeric(5);
    SampleEntity sampleEntity2 = new SampleEntityBuilder(documentId2)
        .message("test test")
        .rate(5)
        .version(System.currentTimeMillis()).build();

    // third document
    String documentId3 = randomNumeric(5);
    SampleEntity sampleEntity3 = new SampleEntityBuilder(documentId3)
        .message("some message")
        .rate(15)
        .version(System.currentTimeMillis()).build();

    indexQueries = getIndexQueries(Arrays.asList(sampleEntity1, sampleEntity2, sampleEntity3));
View Full Code Here


  @Test
  public void shouldReturnListForGivenStringQuery() {
    // given
    // first document
    String documentId = randomNumeric(5);
    SampleEntity sampleEntity1 = new SampleEntityBuilder(documentId)
        .message("test message")
        .version(System.currentTimeMillis()).build();

    // second document
    String documentId2 = randomNumeric(5);
    SampleEntity sampleEntity2 = new SampleEntityBuilder(documentId2)
        .message("test test")
        .rate(5)
        .version(System.currentTimeMillis()).build();

    // third document
    String documentId3 = randomNumeric(5);
    SampleEntity sampleEntity3 = new SampleEntityBuilder(documentId3)
        .message("some message")
        .rate(15)
        .version(System.currentTimeMillis()).build();

    List<IndexQuery> indexQueries = getIndexQueries(Arrays.asList(sampleEntity1, sampleEntity2, sampleEntity3));
View Full Code Here

   */
  @Test
  public void shouldCountCustomMethodWithBefore() {
    // given
    String documentId = randomNumeric(5);
    SampleEntity sampleEntity = new SampleEntity();
    sampleEntity.setId(documentId);
    sampleEntity.setType("test");
    sampleEntity.setRate(10);
    sampleEntity.setMessage("some message");

    repository.save(sampleEntity);

    documentId = randomNumeric(5);
    SampleEntity sampleEntity2 = new SampleEntity();
    sampleEntity2.setId(documentId);
    sampleEntity2.setType("test");
    sampleEntity2.setRate(20);
    sampleEntity2.setMessage("some message");

    repository.save(sampleEntity2);

    // when
    long count = repository.countByRateBefore(10);
View Full Code Here

    //given
    String documentId = randomNumeric(5);
    String messageBeforeUpdate = "some test message";
    String messageAfterUpdate = "test message";

    SampleEntity sampleEntity = new SampleEntityBuilder(documentId)
        .message(messageBeforeUpdate)
        .version(System.currentTimeMillis()).build();

    IndexQuery indexQuery = getIndexQuery(sampleEntity);

    elasticsearchTemplate.index(indexQuery);
    elasticsearchTemplate.refresh(SampleEntity.class, true);

    IndexRequest indexRequest = new IndexRequest();
    indexRequest.source("message", messageAfterUpdate);
    UpdateQuery updateQuery = new UpdateQueryBuilder().withId(documentId)
        .withClass(SampleEntity.class).withIndexRequest(indexRequest).build();
    // when
    elasticsearchTemplate.update(updateQuery);
    //then
    GetQuery getQuery = new GetQuery();
    getQuery.setId(documentId);
    SampleEntity indexedEntity = elasticsearchTemplate.queryForObject(getQuery, SampleEntity.class);
    assertThat(indexedEntity.getMessage(), is(messageAfterUpdate));
  }
View Full Code Here

    //when
    elasticsearchTemplate.update(updateQuery);
    //then
    GetQuery getQuery = new GetQuery();
    getQuery.setId(documentId);
    SampleEntity indexedEntity = elasticsearchTemplate.queryForObject(getQuery, SampleEntity.class);
    assertThat(indexedEntity.getMessage(), is(message));
  }
View Full Code Here

    //given
    String documentId = randomNumeric(5);
    String actualMessage = "some test message";
    String highlightedMessage = "some <em>test</em> message";

    SampleEntity sampleEntity = new SampleEntityBuilder(documentId)
        .message(actualMessage)
        .version(System.currentTimeMillis()).build();

    IndexQuery indexQuery = getIndexQuery(sampleEntity);

    elasticsearchTemplate.index(indexQuery);
    elasticsearchTemplate.refresh(SampleEntity.class, true);

    SearchQuery searchQuery = new NativeSearchQueryBuilder()
        .withQuery(termQuery("message", "test"))
        .withHighlightFields(new HighlightBuilder.Field("message"))
        .build();

    Page<SampleEntity> sampleEntities = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class, new SearchResultMapper() {
      @Override
      public <T> FacetedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
        List<SampleEntity> chunk = new ArrayList<SampleEntity>();
        for (SearchHit searchHit : response.getHits()) {
          if (response.getHits().getHits().length <= 0) {
            return null;
          }
          SampleEntity user = new SampleEntity();
          user.setId(searchHit.getId());
          user.setMessage((String) searchHit.getSource().get("message"));
          user.setHighlightedMessage(searchHit.getHighlightFields().get("message").fragments()[0].toString());
          chunk.add(user);
        }
        if (chunk.size() > 0) {
          return new FacetedPageImpl<T>((List<T>) chunk);
        }
View Full Code Here

   */
  @Test
  public void shouldCountCustomMethodWithAfter() {
    // given
    String documentId = randomNumeric(5);
    SampleEntity sampleEntity = new SampleEntity();
    sampleEntity.setId(documentId);
    sampleEntity.setType("test");
    sampleEntity.setRate(10);
    sampleEntity.setMessage("some message");

    repository.save(sampleEntity);

    documentId = randomNumeric(5);
    SampleEntity sampleEntity2 = new SampleEntity();
    sampleEntity2.setId(documentId);
    sampleEntity2.setType("test");
    sampleEntity2.setRate(0);
    sampleEntity2.setMessage("some message");

    repository.save(sampleEntity2);

    // when
    long count = repository.countByRateAfter(10);
View Full Code Here

  @Test
  public void shouldDeleteSpecifiedTypeFromAnIndex() {
    // given
    String documentId = randomNumeric(5);
    SampleEntity sampleEntity = new SampleEntityBuilder(documentId)
        .message("some message")
        .version(System.currentTimeMillis()).build();

    IndexQuery indexQuery = getIndexQuery(sampleEntity);
View Full Code Here

  @Test
  public void shouldDeleteDocumentBySpecifiedTypeUsingDeleteQuery() {
    // given
    String documentId = randomNumeric(5);
    SampleEntity sampleEntity = new SampleEntityBuilder(documentId)
        .message("some message")
        .version(System.currentTimeMillis()).build();

    IndexQuery indexQuery = getIndexQuery(sampleEntity);
View Full Code Here

    Page<SampleEntity> page = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class, new SearchResultMapper() {
      @Override
      public <T> FacetedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
        List<SampleEntity> values = new ArrayList<SampleEntity>();
        for (SearchHit searchHit : response.getHits()) {
          SampleEntity sampleEntity = new SampleEntity();
          sampleEntity.setId(searchHit.getId());
          sampleEntity.setMessage((String) searchHit.getSource().get("message"));
          values.add(sampleEntity);
        }
        return new FacetedPageImpl<T>((List<T>) values);
      }
    });
View Full Code Here

TOP

Related Classes of org.springframework.data.elasticsearch.entities.SampleEntity

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.