@@ -97,6 +97,28 @@ void shouldEscapeStringsInQueryParameters() throws Exception {
97
97
.isEqualTo ("{\" bool\" :{\" must\" : [{\" match\" : {\" prefix\" : {\" name\" : \" hello \\ \" Stranger\\ \" \" }}]}}" );
98
98
}
99
99
100
+ @ Test // #1858
101
+ @ DisplayName ("should only quote String query parameters" )
102
+ void shouldOnlyEscapeStringQueryParameters () throws Exception {
103
+ org .springframework .data .elasticsearch .core .query .Query query = createQuery ("findByAge" , Integer .valueOf (30 ));
104
+
105
+ assertThat (query ).isInstanceOf (StringQuery .class );
106
+ assertThat (((StringQuery ) query ).getSource ()).isEqualTo ("{ 'bool' : { 'must' : { 'term' : { 'age' : 30 } } } }" );
107
+
108
+ }
109
+
110
+ @ Test // #1858
111
+ @ DisplayName ("should only quote String collection query parameters" )
112
+ void shouldOnlyEscapeStringCollectionQueryParameters () throws Exception {
113
+ org .springframework .data .elasticsearch .core .query .Query query = createQuery ("findByAgeIn" ,
114
+ new ArrayList <>(Arrays .asList (30 , 35 , 40 )));
115
+
116
+ assertThat (query ).isInstanceOf (StringQuery .class );
117
+ assertThat (((StringQuery ) query ).getSource ())
118
+ .isEqualTo ("{ 'bool' : { 'must' : { 'term' : { 'age' : [30,35,40] } } } }" );
119
+
120
+ }
121
+
100
122
@ Test // #1858
101
123
@ DisplayName ("should escape Strings in collection query parameters" )
102
124
void shouldEscapeStringsInCollectionsQueryParameters () throws Exception {
@@ -132,6 +154,12 @@ private ElasticsearchQueryMethod getQueryMethod(String name, Class<?>... paramet
132
154
133
155
private interface SampleRepository extends Repository <Person , String > {
134
156
157
+ @ Query ("{ 'bool' : { 'must' : { 'term' : { 'age' : ?0 } } } }" )
158
+ List <Person > findByAge (Integer age );
159
+
160
+ @ Query ("{ 'bool' : { 'must' : { 'term' : { 'age' : ?0 } } } }" )
161
+ List <Person > findByAgeIn (ArrayList <Integer > age );
162
+
135
163
@ Query ("{ 'bool' : { 'must' : { 'term' : { 'name' : '?0' } } } }" )
136
164
Person findByName (String name );
137
165
@@ -150,16 +178,27 @@ Person findWithRepeatedPlaceholder(String arg0, String arg1, String arg2, String
150
178
* @author Rizwan Idrees
151
179
* @author Mohsin Husen
152
180
* @author Artur Konczak
181
+ * @author Niklas Herder
153
182
*/
154
183
155
184
@ Document (indexName = "test-index-person-query-unittest" )
156
185
static class Person {
157
186
187
+ @ Nullable public int age ;
158
188
@ Nullable @ Id private String id ;
159
189
@ Nullable private String name ;
160
190
@ Nullable @ Field (type = FieldType .Nested ) private List <Car > car ;
161
191
@ Nullable @ Field (type = FieldType .Nested , includeInParent = true ) private List <Book > books ;
162
192
193
+ @ Nullable
194
+ public int getAge () {
195
+ return age ;
196
+ }
197
+
198
+ public void setAge (int age ) {
199
+ this .age = age ;
200
+ }
201
+
163
202
@ Nullable
164
203
public String getId () {
165
204
return id ;
0 commit comments