Package org.springframework.data.elasticsearch.entities

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


  @Test
  public void shouldSortByGivenField() {
    // todo
    // given
    String documentId = randomNumeric(5);
    SampleEntity sampleEntity = new SampleEntity();
    sampleEntity.setId(documentId);
    sampleEntity.setMessage("world");
    repository.save(sampleEntity);

    String documentId2 = randomNumeric(5);
    SampleEntity sampleEntity2 = new SampleEntity();
    sampleEntity2.setId(documentId2);
    sampleEntity2.setMessage("hello");
    repository.save(sampleEntity2);
    // when
    Iterable<SampleEntity> sampleEntities = repository.findAll(new Sort(new Sort.Order(Sort.Direction.ASC, "message")));
    // then
    assertThat(sampleEntities, is(notNullValue()));
View Full Code Here


  private static List<SampleEntity> createSampleEntitiesWithMessage(String message, int numberOfEntities) {
    List<SampleEntity> sampleEntities = new ArrayList<SampleEntity>();
    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());
      sampleEntities.add(sampleEntity);
    }
    return sampleEntities;
  }
View Full Code Here

  @Test
  public void shouldExecuteCustomMethodWithNearPointAndDistance() {
    // given
    String documentId = randomNumeric(5);
    SampleEntity sampleEntity = new SampleEntity();
    sampleEntity.setId(documentId);
    sampleEntity.setType("test");
    sampleEntity.setRate(10);
    sampleEntity.setMessage("foo");
    sampleEntity.setLocation(new GeoPoint(45.7806d, 3.0875d));

    repository.save(sampleEntity);

    // when
    Page<SampleEntity> page = repository.findByLocationNear(new Point(3.0875d, 45.7806d), new Distance(2, Metrics.KILOMETERS), new PageRequest(0, 10));
View Full Code Here

   */
  @Test
  public void shouldReturnCountForGivenCriteriaQuery() {
    // 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);
View Full Code Here

  @Test
  public void shouldReturnCountForGivenSearchQuery() {
    // 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);
View Full Code Here

  @Test
  public void shouldReturnObjectForGivenId() {
    // given
    String documentId = randomNumeric(5);
    SampleEntity sampleEntity = new SampleEntityBuilder(documentId).message("some message")
        .version(System.currentTimeMillis()).build();
    IndexQuery indexQuery = getIndexQuery(sampleEntity);
    elasticsearchTemplate.index(indexQuery);
    // when
    GetQuery getQuery = new GetQuery();
    getQuery.setId(documentId);
    SampleEntity sampleEntity1 = elasticsearchTemplate.queryForObject(getQuery, SampleEntity.class);
    // then
    assertNotNull("entity can't be null....", sampleEntity1);
    assertEquals(sampleEntity, sampleEntity1);
  }
View Full Code Here

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

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

    indexQueries = getIndexQueries(Arrays.asList(sampleEntity1, sampleEntity2));

    elasticsearchTemplate.bulkIndex(indexQueries);
View Full Code Here

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

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

    indexQueries = getIndexQueries(Arrays.asList(sampleEntity1, sampleEntity2));

    elasticsearchTemplate.bulkIndex(indexQueries);
    elasticsearchTemplate.refresh(SampleEntity.class, true);

    // when
    SearchQuery query = new NativeSearchQueryBuilder()
        .withIds(Arrays.asList(documentId, documentId2))
        .withFields("message", "type")
        .build();
    LinkedList<SampleEntity> sampleEntities = elasticsearchTemplate.multiGet(query, SampleEntity.class, new MultiGetResultMapper() {
      @Override
      public <T> LinkedList<T> mapResults(MultiGetResponse responses, Class<T> clazz) {
        LinkedList<T> list = new LinkedList<T>();
        for (MultiGetItemResponse response : responses.getResponses()) {
          SampleEntity entity = new SampleEntity();
          entity.setId(response.getResponse().getId());
          entity.setMessage((String) response.getResponse().getField("message").getValue());
          entity.setType((String) response.getResponse().getField("type").getValue());
          list.add((T) entity);
        }
        return list;
      }
    });
View Full Code Here

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

    repository.save(sampleEntity);

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

    repository.save(sampleEntity2);

    // when
    long count = repository.countByType("test");
View Full Code Here

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

    IndexQuery indexQuery = getIndexQuery(sampleEntity);

    elasticsearchTemplate.index(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.