Search in sources :

Example 36 with CriteriaQuery

use of org.springframework.data.elasticsearch.core.query.CriteriaQuery in project spring-data-elasticsearch by spring-projects.

the class GeoJsonIntegrationTests method shouldFindWithinObjectsWithCriteriaQuery.

// DATAES-931
@Test
@DisplayName("should find within objects with Criteria query")
void shouldFindWithinObjectsWithCriteriaQuery() {
    CriteriaQuery query = new CriteriaQuery(new Criteria("area").within(geoShape5To35));
    SearchHits<Area> searchHits = operations.search(query, Area.class);
    assertThat(searchHits.getTotalHits()).isEqualTo(1L);
    assertThat(searchHits.getSearchHit(0).getId()).isEqualTo("area10To20");
}
Also used : CriteriaQuery(org.springframework.data.elasticsearch.core.query.CriteriaQuery) Criteria(org.springframework.data.elasticsearch.core.query.Criteria) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 37 with CriteriaQuery

use of org.springframework.data.elasticsearch.core.query.CriteriaQuery in project spring-data-elasticsearch by spring-projects.

the class GeoJsonIntegrationTests method shouldFindContainsObjectsWithCriteriaQuery.

// DATAES-931
@Test
@DisplayName("should find contains objects with Criteria query")
void shouldFindContainsObjectsWithCriteriaQuery() {
    CriteriaQuery query = new CriteriaQuery(new Criteria("area").contains(geoShape32To37));
    SearchHits<Area> searchHits = operations.search(query, Area.class);
    assertThat(searchHits.getTotalHits()).isEqualTo(1L);
    assertThat(searchHits.getSearchHit(0).getId()).isEqualTo("area30To40");
}
Also used : CriteriaQuery(org.springframework.data.elasticsearch.core.query.CriteriaQuery) Criteria(org.springframework.data.elasticsearch.core.query.Criteria) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 38 with CriteriaQuery

use of org.springframework.data.elasticsearch.core.query.CriteriaQuery in project spring-advanced-training by arnosthavelka.

the class CityService method search.

public SearchHits<City> search(String name, String country, String subcountry, Pageable pageable) {
    var index = IndexCoordinates.of(City.INDEX);
    CriteriaQuery query = buildSearchQuery(name, country, subcountry);
    query.setPageable(pageable);
    return esTemplate.search(query, City.class, index);
}
Also used : CriteriaQuery(org.springframework.data.elasticsearch.core.query.CriteriaQuery)

Aggregations

CriteriaQuery (org.springframework.data.elasticsearch.core.query.CriteriaQuery)38 Criteria (org.springframework.data.elasticsearch.core.query.Criteria)30 Test (org.junit.jupiter.api.Test)29 SpringIntegrationTest (org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)16 DisplayName (org.junit.jupiter.api.DisplayName)10 Query (org.springframework.data.elasticsearch.core.query.Query)8 MemberDocument (com.example.elasticsearch.member.domain.MemberDocument)4 SearchRequest (org.elasticsearch.action.search.SearchRequest)4 SearchHits (org.springframework.data.elasticsearch.core.SearchHits)2 StringQuery (org.springframework.data.elasticsearch.core.query.StringQuery)2 ParametersParameterAccessor (org.springframework.data.repository.query.ParametersParameterAccessor)2 Method (java.lang.reflect.Method)1 LocalDate (java.time.LocalDate)1 Date (java.util.Date)1 List (java.util.List)1 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)1 SearchHitsImpl (org.springframework.data.elasticsearch.core.SearchHitsImpl)1 SearchPage (org.springframework.data.elasticsearch.core.SearchPage)1 GeoJsonPoint (org.springframework.data.elasticsearch.core.geo.GeoJsonPoint)1 GeoPoint (org.springframework.data.elasticsearch.core.geo.GeoPoint)1