use of org.springframework.data.elasticsearch.core.query.CriteriaQuery in project spring-data-elasticsearch by spring-projects.
the class CriteriaQueryMappingUnitTests method shouldMapNamesAndValueInNestedEntitiesWithSubfields.
// #1753
@Test
@DisplayName("should map names and value in nested entities with sub-fields")
void shouldMapNamesAndValueInNestedEntitiesWithSubfields() throws JSONException {
String expected = //
"{\n" + //
" \"bool\": {\n" + //
" \"must\": [\n" + //
" {\n" + //
" \"nested\": {\n" + //
" \"query\": {\n" + //
" \"query_string\": {\n" + //
" \"query\": \"Foobar\",\n" + //
" \"fields\": [\n" + //
" \"per-sons.nick-name.keyword^1.0\"\n" + //
" ]\n" + //
" }\n" + //
" },\n" + //
" \"path\": \"per-sons\"\n" + //
" }\n" + //
" }\n" + //
" ]\n" + //
" }\n" + //
"}\n";
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("persons.nickName.keyword").is("Foobar"));
mappingElasticsearchConverter.updateQuery(criteriaQuery, House.class);
String queryString = new CriteriaQueryProcessor().createQuery(criteriaQuery.getCriteria()).toString();
assertEquals(expected, queryString, false);
}
use of org.springframework.data.elasticsearch.core.query.CriteriaQuery in project spring-data-elasticsearch by spring-projects.
the class CriteriaQueryMappingUnitTests method shouldMapNamesAndConvertValuesInCriteriaQuery.
// endregion
// region tests
// DATAES-716
@Test
void shouldMapNamesAndConvertValuesInCriteriaQuery() throws JSONException {
// use POJO properties and types in the query building
CriteriaQuery criteriaQuery = new //
CriteriaQuery(//
new Criteria("birthDate").between(LocalDate.of(1989, 11, 9), //
LocalDate.of(1990, 11, 9)).or("birthDate").is(//
LocalDate.of(2019, 12, 28)));
// mapped field name and converted parameter
String expected = //
'{' + //
" \"bool\" : {" + //
" \"should\" : [" + //
" {" + //
" \"range\" : {" + //
" \"birth-date\" : {" + //
" \"from\" : \"09.11.1989\"," + //
" \"to\" : \"09.11.1990\"," + //
" \"include_lower\" : true," + //
" \"include_upper\" : true" + //
" }" + //
" }" + //
" }," + //
" {" + //
" \"query_string\" : {" + //
" \"query\" : \"28.12.2019\"," + //
" \"fields\" : [" + //
" \"birth-date^1.0\"" + //
" ]" + //
" }" + //
" }" + //
" ]" + //
" }" + //
'}';
mappingElasticsearchConverter.updateQuery(criteriaQuery, Person.class);
String queryString = new CriteriaQueryProcessor().createQuery(criteriaQuery.getCriteria()).toString();
assertEquals(expected, queryString, false);
}
use of org.springframework.data.elasticsearch.core.query.CriteriaQuery in project spring-data-elasticsearch by spring-projects.
the class CriteriaQueryMappingUnitTests method shouldMapNamesAndValuesInSubCriteriaQuery.
// DATAES-706
@Test
void shouldMapNamesAndValuesInSubCriteriaQuery() throws JSONException {
CriteriaQuery criteriaQuery = new //
CriteriaQuery(//
new Criteria("firstName").matches("John").subCriteria(//
new Criteria("birthDate").between(LocalDate.of(1989, 11, 9), //
LocalDate.of(1990, 11, 9)).or("birthDate").is(LocalDate.of(2019, 12, 28))));
String expected = //
"{\n" + //
" \"bool\": {\n" + //
" \"must\": [\n" + //
" {\n" + //
" \"match\": {\n" + //
" \"first-name\": {\n" + //
" \"query\": \"John\"\n" + //
" }\n" + //
" }\n" + //
" },\n" + //
" {\n" + //
" \"bool\": {\n" + //
" \"should\": [\n" + //
" {\n" + //
" \"range\": {\n" + //
" \"birth-date\": {\n" + //
" \"from\": \"09.11.1989\",\n" + //
" \"to\": \"09.11.1990\",\n" + //
" \"include_lower\": true,\n" + //
" \"include_upper\": true\n" + //
" }\n" + //
" }\n" + //
" },\n" + //
" {\n" + //
" \"query_string\": {\n" + //
" \"query\": \"28.12.2019\",\n" + //
" \"fields\": [\n" + //
" \"birth-date^1.0\"\n" + //
" ]\n" + //
" }\n" + //
" }\n" + //
" ]\n" + //
" }\n" + //
" }\n" + //
" ]\n" + //
" }\n" + //
"}\n";
mappingElasticsearchConverter.updateQuery(criteriaQuery, Person.class);
String queryString = new CriteriaQueryProcessor().createQuery(criteriaQuery.getCriteria()).toString();
assertEquals(expected, queryString, false);
}
use of org.springframework.data.elasticsearch.core.query.CriteriaQuery in project spring-data-elasticsearch by spring-projects.
the class CriteriaQueryMappingUnitTests method shouldMapNamesAndValueInNestedEntities.
// #1753
@Test
@DisplayName("should map names and value in nested entities")
void shouldMapNamesAndValueInNestedEntities() throws JSONException {
String expected = //
"{\n" + //
" \"bool\": {\n" + //
" \"must\": [\n" + //
" {\n" + //
" \"nested\": {\n" + //
" \"query\": {\n" + //
" \"query_string\": {\n" + //
" \"query\": \"03.10.1999\",\n" + //
" \"fields\": [\n" + //
" \"per-sons.birth-date^1.0\"\n" + //
" ]\n" + //
" }\n" + //
" },\n" + //
" \"path\": \"per-sons\"\n" + //
" }\n" + //
" }\n" + //
" ]\n" + //
" }\n" + //
"}\n";
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("persons.birthDate").is(LocalDate.of(1999, 10, 3)));
mappingElasticsearchConverter.updateQuery(criteriaQuery, House.class);
String queryString = new CriteriaQueryProcessor().createQuery(criteriaQuery.getCriteria()).toString();
assertEquals(expected, queryString, false);
}
use of org.springframework.data.elasticsearch.core.query.CriteriaQuery in project spring-data-elasticsearch by spring-projects.
the class CriteriaQueryMappingUnitTests method shouldMapNamesAndValueInObjectEntities.
// #1761
@Test
@DisplayName("should map names and value in object entities")
void shouldMapNamesAndValueInObjectEntities() throws JSONException {
String expected = //
"{\n" + //
" \"bool\": {\n" + //
" \"must\": [\n" + //
" {\n" + //
" \"query_string\": {\n" + //
" \"query\": \"03.10.1999\",\n" + //
" \"fields\": [\n" + //
" \"per-sons.birth-date^1.0\"\n" + //
" ]\n" + //
" }\n" + //
" }\n" + //
" ]\n" + //
" }\n" + //
"}\n";
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("persons.birthDate").is(LocalDate.of(1999, 10, 3)));
mappingElasticsearchConverter.updateQuery(criteriaQuery, ObjectWithPerson.class);
String queryString = new CriteriaQueryProcessor().createQuery(criteriaQuery.getCriteria()).toString();
assertEquals(expected, queryString, false);
}
Aggregations