25
25
import co .elastic .clients .elasticsearch ._types .Time ;
26
26
import co .elastic .clients .elasticsearch ._types .aggregations .Aggregate ;
27
27
import co .elastic .clients .elasticsearch ._types .mapping .Property ;
28
- import co .elastic .clients .elasticsearch ._types .query_dsl .DecayFunction ;
29
28
import co .elastic .clients .elasticsearch ._types .query_dsl .DistanceFeatureQuery ;
30
- import co .elastic .clients .elasticsearch ._types .query_dsl .FunctionScore ;
31
- import co .elastic .clients .elasticsearch ._types .query_dsl .FunctionScoreBuilders ;
32
- import co .elastic .clients .elasticsearch ._types .query_dsl .FunctionScoreQuery ;
33
29
import co .elastic .clients .elasticsearch ._types .query_dsl .MultiValueMode ;
34
30
import co .elastic .clients .elasticsearch ._types .query_dsl .Query ;
35
- import co .elastic .clients .elasticsearch ._types .query_dsl .RangeQuery ;
36
31
import co .elastic .clients .elasticsearch ._types .query_dsl .RangeRelation ;
37
32
import co .elastic .clients .elasticsearch ._types .query_dsl .TermRangeQuery ;
38
- import co .elastic .clients .elasticsearch ._types .query_dsl .UntypedRangeQuery ;
39
- import co .elastic .clients .elasticsearch .core .SearchRequest ;
40
33
import co .elastic .clients .elasticsearch .core .SearchResponse ;
41
- import co .elastic .clients .json .JsonData ;
42
- import co .elastic .clients .json .JsonpUtils ;
43
34
import co .elastic .clients .testkit .ModelTestCase ;
44
35
import jakarta .json .Json ;
45
36
import jakarta .json .JsonObject ;
@@ -120,7 +111,7 @@ public void testOpenInternalUnion() {
120
111
public void testOpenTypedKeysUnion () {
121
112
String requiredFields =
122
113
"{\" took\" :1,\" timed_out\" :false,\" _shards\" :{\" failed\" :0.0,\" successful\" :1.0,\" total\" :1.0}," +
123
- "\" hits\" :{\" total\" :{\" relation\" :\" eq\" ,\" value\" :0},\" hits\" :[]}}" ;
114
+ "\" hits\" :{\" total\" :{\" relation\" :\" eq\" ,\" value\" :0},\" hits\" :[]}}" ;
124
115
125
116
String customAgg = "{\" bar\" :42}" ;
126
117
@@ -152,16 +143,17 @@ public void testOpenTypedKeysUnion() {
152
143
public void testUntaggedUnion () {
153
144
// Range queries
154
145
Query numberRangeQuery = Query .of (q -> q .range (r -> r
155
- .number (n -> n
156
- .field ("age" )
157
- .gte (10D )
158
- .lte (20D )
159
- .boost (1.0F )
160
- .relation (RangeRelation .Contains ))));
146
+ .number (n -> n
147
+ .field ("age" )
148
+ .gte (10D )
149
+ .lte (20D )
150
+ .boost (1.0F )
151
+ .relation (RangeRelation .Contains ))));
161
152
162
- String expectedNumberRangeQuery = "{\" range\" :{\" age\" :{\" boost\" :1.0,\" relation\" :\" contains\" ,\" gte\" :10.0,\" lte\" :20.0}}}" ;
153
+ String expectedNumberRangeQuery = "{\" range\" :{\" age\" :{\" boost\" :1.0,\" relation\" :\" contains\" ," +
154
+ "\" gte\" :10.0,\" lte\" :20.0}}}" ;
163
155
164
- assertEquals (expectedNumberRangeQuery ,toJson (numberRangeQuery ));
156
+ assertEquals (expectedNumberRangeQuery , toJson (numberRangeQuery ));
165
157
166
158
Query dateRangeQuery = Query .of (q -> q .range (r -> r
167
159
.date (d -> d
@@ -172,9 +164,10 @@ public void testUntaggedUnion() {
172
164
.format ("some-format" )
173
165
.relation (RangeRelation .Contains ))));
174
166
175
- String expectedDateRangeQuery = "{\" range\" :{\" day\" :{\" boost\" :1.0,\" relation\" :\" contains\" ,\" gte\" :\" 20-06-24\" ,\" lte\" :\" 20-07-24\" },\" format\" :\" some-format\" }}" ;
167
+ String expectedDateRangeQuery = "{\" range\" :{\" day\" :{\" boost\" :1.0,\" relation\" :\" contains\" ," +
168
+ "\" gte\" :\" 20-06-24\" ,\" lte\" :\" 20-07-24\" },\" format\" :\" some-format\" }}" ;
176
169
177
- assertEquals (expectedDateRangeQuery ,toJson (dateRangeQuery ));
170
+ assertEquals (expectedDateRangeQuery , toJson (dateRangeQuery ));
178
171
179
172
Query termRangeQuery = Query .of (q -> q .range (r -> r
180
173
.term (d -> d
@@ -184,12 +177,13 @@ public void testUntaggedUnion() {
184
177
.boost (1.0F )
185
178
.relation (RangeRelation .Contains ))));
186
179
187
- String expectedTermRangeQuery = "{\" range\" :{\" word\" :{\" boost\" :1.0,\" relation\" :\" contains\" ,\" gte\" :\" some\" ,\" lte\" :\" word\" }}}" ;
180
+ String expectedTermRangeQuery = "{\" range\" :{\" word\" :{\" boost\" :1.0,\" relation\" :\" contains\" ," +
181
+ "\" gte\" :\" some\" ,\" lte\" :\" word\" }}}" ;
188
182
189
- assertEquals (expectedTermRangeQuery ,toJson (termRangeQuery ));
183
+ assertEquals (expectedTermRangeQuery , toJson (termRangeQuery ));
190
184
191
185
String jsonNumberRangeQuery = "{\n " +
192
- " \" range\" : {\n " +
186
+ " \" range\" : {\n " +
193
187
" \" age\" : {\n " +
194
188
" \" gte\" : 10,\n " +
195
189
" \" lte\" : 20,\n " +
@@ -206,7 +200,8 @@ public void testUntaggedUnion() {
206
200
assertEquals (20 , numberRangeQueryFromJson .range ().untyped ().lte ().to (Integer .class ));
207
201
assertEquals (RangeRelation .Contains , numberRangeQueryFromJson .range ().untyped ().relation ());
208
202
209
- Query converted = TermRangeQuery .of (trq -> trq .field ("a" ).gte ("b" ).lte ("c" ))._toRangeQuery ()._toQuery ();
203
+ Query converted =
204
+ TermRangeQuery .of (trq -> trq .field ("a" ).gte ("b" ).lte ("c" ))._toRangeQuery ()._toQuery ();
210
205
assertTrue (converted .isRange ());
211
206
212
207
// Distance feature queries
@@ -219,8 +214,10 @@ public void testUntaggedUnion() {
219
214
.pivot ("1000m" )
220
215
.origin (GeoLocation .of (gl -> gl .latlon (LatLonGeoLocation .of (ll -> ll .lon (-71.3 ).lat (41.15 ))))))))));
221
216
222
- String expectedGeoDistFeatQuery = "{\" bool\" :{\" must\" :[{\" match_all\" :{}}],\" should\" :[{\" distance_feature\" :{\" origin\" :{\" lat\" :41.15,\" lon\" :-71.3},\" pivot\" :\" 1000m\" ,\" field\" :\" location\" }}]}}" ;
223
- assertEquals (expectedGeoDistFeatQuery ,toJson (geoDistanceFeatureQuery ));
217
+ String expectedGeoDistFeatQuery = "{\" bool\" :{\" must\" :[{\" match_all\" :{}}]," +
218
+ "\" should\" :[{\" distance_feature\" :{\" origin\" :{\" lat\" :41.15,\" lon\" :-71.3}," +
219
+ "\" pivot\" :\" 1000m\" ,\" field\" :\" location\" }}]}}" ;
220
+ assertEquals (expectedGeoDistFeatQuery , toJson (geoDistanceFeatureQuery ));
224
221
225
222
226
223
Query dateDistanceFeatureQuery = Query .of (q -> q .bool (b -> b
@@ -231,8 +228,9 @@ public void testUntaggedUnion() {
231
228
.pivot (Time .of (t -> t .time ("7d" )))
232
229
.origin ("now" ))))));
233
230
234
- String expectedDateDistFeatQuery = "{\" bool\" :{\" must\" :[{\" match_all\" :{}}],\" should\" :[{\" distance_feature\" :{\" origin\" :\" now\" ,\" pivot\" :\" 7d\" ,\" field\" :\" date\" }}]}}" ;
235
- assertEquals (expectedDateDistFeatQuery ,toJson (dateDistanceFeatureQuery ));
231
+ String expectedDateDistFeatQuery = "{\" bool\" :{\" must\" :[{\" match_all\" :{}}]," +
232
+ "\" should\" :[{\" distance_feature\" :{\" origin\" :\" now\" ,\" pivot\" :\" 7d\" ,\" field\" :\" date\" }}]}}" ;
233
+ assertEquals (expectedDateDistFeatQuery , toJson (dateDistanceFeatureQuery ));
236
234
237
235
String distDateQuery = "{\n " +
238
236
" \" bool\" : {\n " +
@@ -251,8 +249,10 @@ public void testUntaggedUnion() {
251
249
252
250
Query distDateQueryFromJson = Query .of (q -> q .withJson (new StringReader (distDateQuery )));
253
251
assertTrue (distDateQueryFromJson .bool ().should ().get (0 ).distanceFeature ().isUntyped ());
254
- assertEquals ("7d" ,distDateQueryFromJson .bool ().should ().get (0 ).distanceFeature ().untyped ().pivot ().to (String .class ));
255
- assertEquals ("date" ,distDateQueryFromJson .bool ().should ().get (0 ).distanceFeature ().untyped ().field ().toString ());
252
+ assertEquals ("7d" ,
253
+ distDateQueryFromJson .bool ().should ().get (0 ).distanceFeature ().untyped ().pivot ().to (String .class ));
254
+ assertEquals ("date" ,
255
+ distDateQueryFromJson .bool ().should ().get (0 ).distanceFeature ().untyped ().field ().toString ());
256
256
257
257
258
258
String distGeoQuery = "{\n " +
@@ -272,8 +272,10 @@ public void testUntaggedUnion() {
272
272
273
273
Query distGeoQueryFromJson = Query .of (q -> q .withJson (new StringReader (distGeoQuery )));
274
274
assertTrue (distGeoQueryFromJson .bool ().should ().get (0 ).distanceFeature ().isUntyped ());
275
- assertEquals ("1000m" ,distGeoQueryFromJson .bool ().should ().get (0 ).distanceFeature ().untyped ().pivot ().to (String .class ));
276
- assertEquals ("location" , distGeoQueryFromJson .bool ().should ().get (0 ).distanceFeature ().untyped ().field ());
275
+ assertEquals ("1000m" ,
276
+ distGeoQueryFromJson .bool ().should ().get (0 ).distanceFeature ().untyped ().pivot ().to (String .class ));
277
+ assertEquals ("location" ,
278
+ distGeoQueryFromJson .bool ().should ().get (0 ).distanceFeature ().untyped ().field ());
277
279
278
280
279
281
Query convertedDist = DistanceFeatureQuery .of (dfq -> dfq .date (d -> d
@@ -289,13 +291,14 @@ public void testUntaggedUnion() {
289
291
.functions (fn -> fn
290
292
.gauss (g -> g
291
293
.date (d -> d .field ("date" ).placement (pl -> pl
292
- .origin ("2013-09-17" )
293
- .scale (Time .of (t -> t .time ("10d" )))
294
- .offset (Time .of (t -> t .time ("5d" )))
295
- .decay (0.5D )))))));
294
+ .origin ("2013-09-17" )
295
+ .scale (Time .of (t -> t .time ("10d" )))
296
+ .offset (Time .of (t -> t .time ("5d" )))
297
+ .decay (0.5D )))))));
296
298
297
- String expectedFunctionScoreQueryGaussDate = "{\" function_score\" :{\" functions\" :[{\" gauss\" :{\" date\" :{\" decay\" :0.5,\" offset\" :\" 5d\" ,\" scale\" :\" 10d\" ,\" origin\" :\" 2013-09-17\" }}}]}}" ;
298
- assertEquals (expectedFunctionScoreQueryGaussDate ,toJson (functionScoreQueryGaussDate ));
299
+ String expectedFunctionScoreQueryGaussDate = "{\" function_score\" :{\" functions\" :[{\" gauss" +
300
+ "\" :{\" date\" :{\" decay\" :0.5,\" offset\" :\" 5d\" ,\" scale\" :\" 10d\" ,\" origin\" :\" 2013-09-17\" }}}]}}" ;
301
+ assertEquals (expectedFunctionScoreQueryGaussDate , toJson (functionScoreQueryGaussDate ));
299
302
300
303
Query functionScoreQueryExpGeo = Query .of (q -> q .functionScore (fs -> fs
301
304
.functions (fn -> fn
@@ -306,8 +309,10 @@ public void testUntaggedUnion() {
306
309
.offset ("2km" )
307
310
.decay (0.5D )))))));
308
311
309
- String expectedFunctionScoreQueryExpGeo = "{\" function_score\" :{\" functions\" :[{\" exp\" :{\" location\" :{\" decay\" :0.5,\" offset\" :\" 2km\" ,\" scale\" :\" 1km\" ,\" origin\" :{\" lat\" :41.15,\" lon\" :-71.3}}}}]}}" ;
310
- assertEquals (expectedFunctionScoreQueryExpGeo ,toJson (functionScoreQueryExpGeo ));
312
+ String expectedFunctionScoreQueryExpGeo = "{\" function_score\" :{\" functions\" :[{\" exp\" :{\" location" +
313
+ "\" :{\" decay\" :0.5,\" offset\" :\" 2km\" ,\" scale\" :\" 1km\" ,\" origin\" :{\" lat\" :41.15,\" lon\" :-71" +
314
+ ".3}}}}]}}" ;
315
+ assertEquals (expectedFunctionScoreQueryExpGeo , toJson (functionScoreQueryExpGeo ));
311
316
312
317
Query functionScoreQueryLinearNumeric = Query .of (q -> q .functionScore (fs -> fs
313
318
.functions (fn -> fn
@@ -318,8 +323,9 @@ public void testUntaggedUnion() {
318
323
.offset (4D )
319
324
.decay (0.5D )))))));
320
325
321
- String expectedFunctionScoreQueryLinearNumeric = "{\" function_score\" :{\" functions\" :[{\" linear\" :{\" nums\" :{\" decay\" :0.5,\" offset\" :4.0,\" scale\" :3.0,\" origin\" :2.0}}}]}}" ;
322
- assertEquals (expectedFunctionScoreQueryLinearNumeric ,toJson (functionScoreQueryLinearNumeric ));
326
+ String expectedFunctionScoreQueryLinearNumeric = "{\" function_score\" :{\" functions\" :[{\" linear" +
327
+ "\" :{\" nums\" :{\" decay\" :0.5,\" offset\" :4.0,\" scale\" :3.0,\" origin\" :2.0}}}]}}" ;
328
+ assertEquals (expectedFunctionScoreQueryLinearNumeric , toJson (functionScoreQueryLinearNumeric ));
323
329
324
330
String funScoreQuery =
325
331
" {\n " +
@@ -342,8 +348,10 @@ public void testUntaggedUnion() {
342
348
343
349
Query funScoreQueryFromJson = Query .of (q -> q .withJson (new StringReader (funScoreQuery )));
344
350
assertTrue (funScoreQueryFromJson .functionScore ().functions ().get (0 ).gauss ().isUntyped ());
345
- assertEquals ("2013-09-17" , funScoreQueryFromJson .functionScore ().functions ().get (0 ).gauss ().untyped ().placement ().origin ().to (String .class ));
346
- assertEquals (MultiValueMode .Avg , funScoreQueryFromJson .functionScore ().functions ().get (0 ).gauss ().untyped ().multiValueMode ());
351
+ assertEquals ("2013-09-17" ,
352
+ funScoreQueryFromJson .functionScore ().functions ().get (0 ).gauss ().untyped ().placement ().origin ().to (String .class ));
353
+ assertEquals (MultiValueMode .Avg ,
354
+ funScoreQueryFromJson .functionScore ().functions ().get (0 ).gauss ().untyped ().multiValueMode ());
347
355
348
356
349
357
}
0 commit comments