Example usage for org.springframework.data.elasticsearch.core.query StringQuery StringQuery

List of usage examples for org.springframework.data.elasticsearch.core.query StringQuery StringQuery

Introduction

In this page you can find the example usage for org.springframework.data.elasticsearch.core.query StringQuery StringQuery.

Prototype

public StringQuery(String source, Pageable pageable, Sort sort) 

Source Link

Usage

From source file:com.github.vanroy.springdata.jest.JestElasticsearchTemplateTests.java

@Test
@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() {
    // given/*from  w w w  . j  a  v  a2s .  c om*/
    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);

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

    StringQuery stringQuery = new StringQuery(matchAllQuery().toString(), new PageRequest(0, 10),
            new Sort(new Sort.Order(Sort.Direction.ASC, "messsage")));
    // when
    Page<SampleEntity> sampleEntities = elasticsearchTemplate.queryForPage(stringQuery, SampleEntity.class);
    // then
    assertThat(sampleEntities.getTotalElements(), is(greaterThanOrEqualTo(1L)));
}

From source file:org.springframework.data.elasticsearch.core.ElasticsearchTemplateTests.java

@Test
@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//www .j  av  a 2s  .com
    // 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);

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

    StringQuery stringQuery = new StringQuery(matchAllQuery().toString(), new PageRequest(0, 10),
            new Sort(new Sort.Order(Sort.Direction.ASC, "messsage")));
    // when
    Page<SampleEntity> sampleEntities = elasticsearchTemplate.queryForPage(stringQuery, SampleEntity.class);
    // then
    assertThat(sampleEntities.getTotalElements(), is(greaterThanOrEqualTo(1L)));
}