Package org.springframework.data.elasticsearch.entities

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


  @Ignore("By default, the search request will fail if there is no mapping associated with a field. The ignore_unmapped option allows to ignore fields that have no mapping and not sort by them")
  public void shouldReturnSortedPageableResultsGivenStringQuery() {
    // todo
    // given
    String documentId = randomNumeric(5);
    SampleEntity sampleEntity = new SampleEntity();
    sampleEntity.setId(documentId);
    sampleEntity.setMessage("some message");
    sampleEntity.setVersion(System.currentTimeMillis());

    IndexQuery indexQuery = new IndexQuery();
    indexQuery.setId(documentId);
    indexQuery.setObject(sampleEntity);
View Full Code Here


   */
  @Test
  public void shouldCountCustomMethodWithBooleanParameter() {
    // given
    String documentId = randomNumeric(5);
    SampleEntity sampleEntity = new SampleEntity();
    sampleEntity.setId(documentId);
    sampleEntity.setType("test");
    sampleEntity.setMessage("foo");
    sampleEntity.setAvailable(true);
    repository.save(sampleEntity);

    // given
    String documentId2 = randomNumeric(5);
    SampleEntity sampleEntity2 = new SampleEntity();
    sampleEntity2.setId(documentId2);
    sampleEntity2.setType("test");
    sampleEntity2.setMessage("bar");
    sampleEntity2.setAvailable(false);
    repository.save(sampleEntity2);
    // when
    long count = repository.countByAvailable(false);
    // then
    assertThat(count, is(equalTo(1L)));
View Full Code Here

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

    IndexQuery indexQuery = getIndexQuery(sampleEntity);

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

    StringQuery stringQuery = new StringQuery(termQuery("id", documentId).toString());
    // when
    SampleEntity sampleEntity1 = elasticsearchTemplate.queryForObject(stringQuery, SampleEntity.class);
    // then
    assertThat(sampleEntity1, is(notNullValue()));
    assertThat(sampleEntity1.getId(), is(equalTo(documentId)));
  }
View Full Code Here

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

    IndexQuery indexQuery = getIndexQuery(sampleEntity);

    elasticsearchTemplate.index(indexQuery);
    elasticsearchTemplate.refresh(SampleEntity.class, true);
    CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").contains("test"));

    // when
    SampleEntity sampleEntity1 = elasticsearchTemplate.queryForObject(criteriaQuery, SampleEntity.class);
    // then
    assertThat(sampleEntity1, is(notNullValue()));
  }
View Full Code Here

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

    IndexQuery indexQuery = getIndexQuery(sampleEntity);

    elasticsearchTemplate.index(indexQuery);
View Full Code Here

        + " we want a painless setup and a completely free search schema, we want to be able to index data simply using JSON over HTTP, "
        + "we want our search server to be always available, we want to be able to start with one machine and scale to hundreds, "
        + "we want real-time search, we want simple multi-tenancy, and we want a solution that is built for the cloud.";

    String documentId1 = randomNumeric(5);
    SampleEntity sampleEntity = new SampleEntityBuilder(documentId1).message(sampleMessage)
        .version(System.currentTimeMillis()).build();

    IndexQuery indexQuery = getIndexQuery(sampleEntity);

    elasticsearchTemplate.index(indexQuery);
View Full Code Here

        @Override
        public <T> FacetedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
          List<SampleEntity> result = new ArrayList<SampleEntity>();
          for (SearchHit searchHit : response.getHits()) {
            String message = searchHit.getFields().get("message").getValue();
            SampleEntity sampleEntity = new SampleEntity();
            sampleEntity.setId(searchHit.getId());
            sampleEntity.setMessage(message);
            result.add(sampleEntity);
          }

          if (result.size() > 0) {
            return new FacetedPageImpl<T>((List<T>) result);
View Full Code Here

          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"));
            chunk.add(user);
          }
          if (chunk.size() > 0) {
            return new FacetedPageImpl<T>((List<T>) chunk);
          }
View Full Code Here

   */
  @Test
  public void shouldCountCustomMethodWithLessThan() {
    // 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);

    String documentId2 = randomNumeric(5);
    SampleEntity sampleEntity2 = new SampleEntity();
    sampleEntity2.setId(documentId2);
    sampleEntity2.setType("test");
    sampleEntity2.setRate(20);
    sampleEntity2.setMessage("some message");
    repository.save(sampleEntity2);

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

  private static List<IndexQuery> createSampleEntitiesWithMessage(String message, int numberOfEntities) {
    List<IndexQuery> indexQueries = new ArrayList<IndexQuery>();
    for (int i = 0; i < numberOfEntities; i++) {
      String documentId = randomNumeric(5);
      SampleEntity sampleEntity = new SampleEntity();
      sampleEntity.setId(documentId);
      sampleEntity.setMessage(message);
      sampleEntity.setRate(2);
      sampleEntity.setVersion(System.currentTimeMillis());
      IndexQuery indexQuery = new IndexQuery();
      indexQuery.setId(documentId);
      indexQuery.setObject(sampleEntity);
      indexQueries.add(indexQuery);
    }
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.