Search in sources :

Example 6 with CriteriaQuery

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

the class GeoIntegrationTests method shouldFindSelectedAuthorMarkerInRangeForGivenCriteriaQuery.

@Test
public void shouldFindSelectedAuthorMarkerInRangeForGivenCriteriaQuery() {
    // given
    loadClassBaseEntities();
    CriteriaQuery geoLocationCriteriaQuery2 = new CriteriaQuery(new Criteria("name").is("Mohsin Husen").and("location").within(new GeoPoint(51.5171d, 0.1062d), "20km"));
    // when
    SearchHits<AuthorMarkerEntity> geoAuthorsForGeoCriteria2 = operations.search(geoLocationCriteriaQuery2, AuthorMarkerEntity.class, authorMarkerIndex);
    // then
    assertThat(geoAuthorsForGeoCriteria2).hasSize(1);
    assertThat(geoAuthorsForGeoCriteria2.getSearchHit(0).getContent().getName()).isEqualTo("Mohsin Husen");
}
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)

Example 7 with CriteriaQuery

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

the class GeoIntegrationTests method shouldFindDoubleAnnotatedGeoMarkersInRangeForGivenCriteriaQuery.

@Test
public void shouldFindDoubleAnnotatedGeoMarkersInRangeForGivenCriteriaQuery() {
    // given
    loadAnnotationBaseEntities();
    CriteriaQuery geoLocationCriteriaQuery = new CriteriaQuery(new Criteria("locationAsArray").within(new GeoPoint(51.001000, 0.10100), "1km"));
    // when
    SearchHits<LocationMarkerEntity> geoAuthorsForGeoCriteria = operations.search(geoLocationCriteriaQuery, LocationMarkerEntity.class, locationMarkerIndex);
    // then
    assertThat(geoAuthorsForGeoCriteria).hasSize(3);
}
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)

Example 8 with CriteriaQuery

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

the class GeoIntegrationTests method shouldFindAnnotatedGeoMarkersInRangeForGivenCriteriaQuery.

@Test
public void shouldFindAnnotatedGeoMarkersInRangeForGivenCriteriaQuery() {
    // given
    loadAnnotationBaseEntities();
    CriteriaQuery geoLocationCriteriaQuery = new CriteriaQuery(new Criteria("locationAsArray").within("51.001000, 0.10100", "1km"));
    // when
    SearchHits<LocationMarkerEntity> geoAuthorsForGeoCriteria = operations.search(geoLocationCriteriaQuery, LocationMarkerEntity.class, locationMarkerIndex);
    // then
    assertThat(geoAuthorsForGeoCriteria).hasSize(3);
}
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)

Example 9 with CriteriaQuery

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

the class GeoIntegrationTests method shouldFindAnnotatedGeoMarkersInRangeForGivenCriteriaQueryUsingGeohashLocation.

@Test
public void shouldFindAnnotatedGeoMarkersInRangeForGivenCriteriaQueryUsingGeohashLocation() {
    // given
    loadAnnotationBaseEntities();
    CriteriaQuery geoLocationCriteriaQuery = new CriteriaQuery(new Criteria("locationAsArray").within("u1044", "3km"));
    // when
    SearchHits<LocationMarkerEntity> geoAuthorsForGeoCriteria = operations.search(geoLocationCriteriaQuery, LocationMarkerEntity.class, locationMarkerIndex);
    // then
    assertThat(geoAuthorsForGeoCriteria).hasSize(3);
}
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)

Example 10 with CriteriaQuery

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

the class GeoIntegrationTests method shouldFindAuthorMarkersInBoxForGivenCriteriaQueryUsingGeoBox.

@Test
public void shouldFindAuthorMarkersInBoxForGivenCriteriaQueryUsingGeoBox() {
    // given
    loadClassBaseEntities();
    CriteriaQuery geoLocationCriteriaQuery3 = new CriteriaQuery(new Criteria("location").boundedBy(new GeoBox(new GeoPoint(53.5171d, 0), new GeoPoint(49.5171d, 0.2062d))));
    // when
    SearchHits<AuthorMarkerEntity> geoAuthorsForGeoCriteria3 = operations.search(geoLocationCriteriaQuery3, AuthorMarkerEntity.class, authorMarkerIndex);
    // then
    assertThat(geoAuthorsForGeoCriteria3).hasSize(2);
    assertThat(geoAuthorsForGeoCriteria3.stream().map(SearchHit::getContent).map(AuthorMarkerEntity::getName)).containsExactlyInAnyOrder("Mohsin Husen", "Rizwan Idrees");
}
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)

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