Search in sources :

Example 11 with CriteriaQuery

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

the class GeoJsonIntegrationTests method shouldFindIntersectingObjectsWithCriteriaQuery.

// DATAES-931
@Test
@DisplayName("should find intersecting objects with Criteria query")
void shouldFindIntersectingObjectsWithCriteriaQuery() {
    CriteriaQuery query = new CriteriaQuery(new Criteria("area").intersects(geoShape15To25));
    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 12 with CriteriaQuery

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

the class GeoJsonIntegrationTests method shouldFindDisjointObjectsWithCriteriaQuery.

// DATAES-931
@Test
@DisplayName("should find disjoint objects with Criteria query")
void shouldFindDisjointObjectsWithCriteriaQuery() {
    CriteriaQuery query = new CriteriaQuery(new Criteria("area").isDisjoint(geoShape15To25));
    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 13 with CriteriaQuery

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

the class SynonymRepositoryTests method shouldDo.

@Test
public void shouldDo() {
    SynonymEntity entry1 = new SynonymEntity();
    entry1.setText("Elizabeth is the english queen");
    SynonymEntity entry2 = new SynonymEntity();
    entry2.setText("Other text");
    repository.save(entry1);
    repository.save(entry2);
    Query query = new CriteriaQuery(new Criteria("text").is("british"));
    SearchHits<SynonymEntity> synonymEntities = operations.search(query, SynonymEntity.class);
    assertThat(synonymEntities).hasSize(1);
}
Also used : Query(org.springframework.data.elasticsearch.core.query.Query) CriteriaQuery(org.springframework.data.elasticsearch.core.query.CriteriaQuery) 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 14 with CriteriaQuery

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

the class RuntimeFieldsIntegrationTests method shouldUseRuntimeFieldFromQueryInSearch.

// #1971
@Test
@DisplayName("should use runtime-field from query in search")
void shouldUseRuntimeFieldFromQueryInSearch() {
    insert("1", "item 1", 13.5);
    insert("2", "item 2", 15);
    Query query = new CriteriaQuery(new Criteria("priceWithTax").greaterThanEqual(16.5));
    RuntimeField runtimeField = new RuntimeField("priceWithTax", "double", "emit(doc['price'].value * 1.19)");
    query.addRuntimeField(runtimeField);
    SearchHits<SomethingToBuy> searchHits = operations.search(query, SomethingToBuy.class);
    assertThat(searchHits.getTotalHits()).isEqualTo(1);
    assertThat(searchHits.getSearchHit(0).getId()).isEqualTo("2");
}
Also used : Query(org.springframework.data.elasticsearch.core.query.Query) CriteriaQuery(org.springframework.data.elasticsearch.core.query.CriteriaQuery) 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 15 with CriteriaQuery

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

the class MappingElasticsearchConverterUnitTests method shouldNotTryToCallPropertyConverterOnUpdatingCriteriaExists.

// #2080
@Test
@DisplayName("should not try to call property converter on updating criteria exists")
void shouldNotTryToCallPropertyConverterOnUpdatingCriteriaExists() {
    // don't care if the query makes no sense, we just add all criteria without values
    Query query = new CriteriaQuery(Criteria.where("fieldWithClassBasedConverter").exists().empty().notEmpty());
    mappingElasticsearchConverter.updateQuery(query, EntityWithCustomValueConverters.class);
}
Also used : CriteriaQuery(org.springframework.data.elasticsearch.core.query.CriteriaQuery) Query(org.springframework.data.elasticsearch.core.query.Query) CriteriaQuery(org.springframework.data.elasticsearch.core.query.CriteriaQuery) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

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