33
33
import org .springframework .core .convert .support .DefaultConversionService ;
34
34
import org .springframework .core .convert .support .GenericConversionService ;
35
35
import org .springframework .data .convert .CustomConversions ;
36
+ import org .springframework .data .elasticsearch .annotations .FieldType ;
36
37
import org .springframework .data .elasticsearch .annotations .ScriptedField ;
37
38
import org .springframework .data .elasticsearch .core .document .Document ;
38
39
import org .springframework .data .elasticsearch .core .document .SearchDocument ;
@@ -1055,12 +1056,22 @@ private void updateCriteria(Criteria criteria, ElasticsearchPersistentEntity<?>
1055
1056
ElasticsearchPersistentEntity <?> currentEntity = persistentEntity ;
1056
1057
ElasticsearchPersistentProperty persistentProperty = null ;
1057
1058
int propertyCount = 0 ;
1059
+ boolean isNested = false ;
1060
+
1058
1061
for (int i = 0 ; i < fieldNames .length ; i ++) {
1059
1062
persistentProperty = currentEntity .getPersistentProperty (fieldNames [i ]);
1060
1063
1061
1064
if (persistentProperty != null ) {
1062
1065
propertyCount ++;
1063
1066
fieldNames [i ] = persistentProperty .getFieldName ();
1067
+
1068
+ org .springframework .data .elasticsearch .annotations .Field fieldAnnotation = persistentProperty
1069
+ .findAnnotation (org .springframework .data .elasticsearch .annotations .Field .class );
1070
+
1071
+ if (fieldAnnotation != null && fieldAnnotation .type () == FieldType .Nested ) {
1072
+ isNested = true ;
1073
+ }
1074
+
1064
1075
try {
1065
1076
currentEntity = mappingContext .getPersistentEntity (persistentProperty .getActualType ());
1066
1077
} catch (Exception e ) {
@@ -1077,7 +1088,7 @@ private void updateCriteria(Criteria criteria, ElasticsearchPersistentEntity<?>
1077
1088
1078
1089
field .setName (String .join ("." , fieldNames ));
1079
1090
1080
- if (propertyCount > 1 ) {
1091
+ if (propertyCount > 1 && isNested ) {
1081
1092
List <String > propertyNames = Arrays .asList (fieldNames );
1082
1093
field .setPath (String .join ("." , propertyNames .subList (0 , propertyCount - 1 )));
1083
1094
}
0 commit comments