mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-05-30 16:52:11 +00:00
Fix subCriteria's not being updated.
Original Pull Request #1670 Closes #1668
This commit is contained in:
parent
0ac1b4af00
commit
e6c6d34948
@ -72,6 +72,7 @@ import org.springframework.util.ObjectUtils;
|
||||
* @author Roman Puchkovskiy
|
||||
* @author Konrad Kurdej
|
||||
* @author Subhobrata Dey
|
||||
* @author Marc Vanbrabant
|
||||
* @since 3.2
|
||||
*/
|
||||
public class MappingElasticsearchConverter
|
||||
@ -805,6 +806,11 @@ public class MappingElasticsearchConverter
|
||||
for (Criteria chainedCriteria : criteriaQuery.getCriteria().getCriteriaChain()) {
|
||||
updateCriteria(chainedCriteria, persistentEntity);
|
||||
}
|
||||
for (Criteria subCriteria : criteriaQuery.getCriteria().getSubCriteria()) {
|
||||
for (Criteria chainedCriteria : subCriteria.getCriteriaChain()) {
|
||||
updateCriteria(chainedCriteria, persistentEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -843,12 +849,6 @@ public class MappingElasticsearchConverter
|
||||
field.setFieldType(fieldAnnotation.type());
|
||||
}
|
||||
}
|
||||
|
||||
for (Criteria subCriteria : criteria.getSubCriteria()) {
|
||||
for (Criteria chainedCriteria : subCriteria.getCriteriaChain()) {
|
||||
updateCriteria(chainedCriteria, persistentEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
// endregion
|
||||
|
||||
|
@ -18,9 +18,7 @@ package org.springframework.data.elasticsearch.core;
|
||||
import static org.skyscreamer.jsonassert.JSONAssert.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Base64;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@ -109,6 +107,155 @@ public class CriteriaQueryMappingUnitTests {
|
||||
assertEquals(expected, queryString, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
// #1668
|
||||
void shouldMapNamesAndConvertValuesInCriteriaQueryForSubCriteria() throws JSONException {
|
||||
|
||||
// use POJO properties and types in the query building
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery( //
|
||||
Criteria.or()
|
||||
.subCriteria( Criteria.where("birthDate") //
|
||||
.between(LocalDate.of(1989, 11, 9), LocalDate.of(1990, 11, 9)) ) //
|
||||
.subCriteria( Criteria.where( "birthDate").is(LocalDate.of(2019, 12, 28)) ) //
|
||||
);
|
||||
|
||||
// mapped field name and converted parameter
|
||||
String expected = "{\n" +
|
||||
" \"bool\" : {\n" +
|
||||
" \"should\" : [\n" +
|
||||
" {\n" +
|
||||
" \"bool\" : {\n" +
|
||||
" \"must\" : [\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" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"adjust_pure_negative\" : true,\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"bool\" : {\n" +
|
||||
" \"must\" : [\n" +
|
||||
" {\n" +
|
||||
" \"query_string\" : {\n" +
|
||||
" \"query\" : \"28.12.2019\",\n" +
|
||||
" \"fields\" : [\n" +
|
||||
" \"birth-date^1.0\"\n" +
|
||||
" ],\n" +
|
||||
" \"type\" : \"best_fields\",\n" +
|
||||
" \"default_operator\" : \"and\",\n" +
|
||||
" \"max_determinized_states\" : 10000,\n" +
|
||||
" \"enable_position_increments\" : true,\n" +
|
||||
" \"fuzziness\" : \"AUTO\",\n" +
|
||||
" \"fuzzy_prefix_length\" : 0,\n" +
|
||||
" \"fuzzy_max_expansions\" : 50,\n" +
|
||||
" \"phrase_slop\" : 0,\n" +
|
||||
" \"escape\" : false,\n" +
|
||||
" \"auto_generate_synonyms_phrase_query\" : true,\n" +
|
||||
" \"fuzzy_transpositions\" : true,\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"adjust_pure_negative\" : true,\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"adjust_pure_negative\" : true,\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
"}"; //
|
||||
|
||||
mappingElasticsearchConverter.updateQuery(criteriaQuery, Person.class);
|
||||
String queryString = new CriteriaQueryProcessor().createQuery(criteriaQuery.getCriteria()).toString();
|
||||
|
||||
assertEquals(expected, queryString, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
// #1668
|
||||
void shouldMapNamesAndConvertValuesInCriteriaQueryForSubCriteriaWithDate() throws JSONException {
|
||||
// use POJO properties and types in the query building
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery( //
|
||||
Criteria.or()
|
||||
.subCriteria( Criteria.where("birthDate") //
|
||||
.between(LocalDate.of(1989, 11, 9), LocalDate.of(1990, 11, 9)) ) //
|
||||
.subCriteria( Criteria.where( "createdDate").is(383745721653L) ) //
|
||||
);
|
||||
|
||||
// mapped field name and converted parameter
|
||||
String expected = "{\n" +
|
||||
" \"bool\" : {\n" +
|
||||
" \"should\" : [\n" +
|
||||
" {\n" +
|
||||
" \"bool\" : {\n" +
|
||||
" \"must\" : [\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" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"adjust_pure_negative\" : true,\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"bool\" : {\n" +
|
||||
" \"must\" : [\n" +
|
||||
" {\n" +
|
||||
" \"query_string\" : {\n" +
|
||||
" \"query\" : \"383745721653\",\n" +
|
||||
" \"fields\" : [\n" +
|
||||
" \"created-date^1.0\"\n" +
|
||||
" ],\n" +
|
||||
" \"type\" : \"best_fields\",\n" +
|
||||
" \"default_operator\" : \"and\",\n" +
|
||||
" \"max_determinized_states\" : 10000,\n" +
|
||||
" \"enable_position_increments\" : true,\n" +
|
||||
" \"fuzziness\" : \"AUTO\",\n" +
|
||||
" \"fuzzy_prefix_length\" : 0,\n" +
|
||||
" \"fuzzy_max_expansions\" : 50,\n" +
|
||||
" \"phrase_slop\" : 0,\n" +
|
||||
" \"escape\" : false,\n" +
|
||||
" \"auto_generate_synonyms_phrase_query\" : true,\n" +
|
||||
" \"fuzzy_transpositions\" : true,\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"adjust_pure_negative\" : true,\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"adjust_pure_negative\" : true,\n" +
|
||||
" \"boost\" : 1.0\n" +
|
||||
" }\n" +
|
||||
"}"; //
|
||||
|
||||
mappingElasticsearchConverter.updateQuery(criteriaQuery, Person.class);
|
||||
String queryString = new CriteriaQueryProcessor().createQuery(criteriaQuery.getCriteria()).toString();
|
||||
|
||||
assertEquals(expected, queryString, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
// DATAES-706
|
||||
void shouldMapNamesAndValuesInSubCriteriaQuery() throws JSONException {
|
||||
@ -197,6 +344,7 @@ public class CriteriaQueryMappingUnitTests {
|
||||
@Nullable @Id String id;
|
||||
@Nullable @Field(name = "first-name") String firstName;
|
||||
@Nullable @Field(name = "last-name") String lastName;
|
||||
@Nullable @Field(name = "created-date", type = FieldType.Date, format = DateFormat.epoch_millis) Date createdDate;
|
||||
@Nullable @Field(name = "birth-date", type = FieldType.Date, format = DateFormat.custom,
|
||||
pattern = "dd.MM.uuuu") LocalDate birthDate;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user