34
34
import org .springframework .data .elasticsearch .annotations .DateFormat ;
35
35
import org .springframework .data .elasticsearch .annotations .Field ;
36
36
import org .springframework .data .elasticsearch .annotations .FieldType ;
37
+ import org .springframework .data .elasticsearch .annotations .InnerField ;
38
+ import org .springframework .data .elasticsearch .annotations .MultiField ;
37
39
import org .springframework .data .elasticsearch .core .convert .GeoConverters ;
38
40
import org .springframework .data .elasticsearch .core .convert .MappingElasticsearchConverter ;
39
41
import org .springframework .data .elasticsearch .core .document .Document ;
@@ -362,6 +364,39 @@ void shouldMapNamesAndValueInNestedEntities() throws JSONException {
362
364
363
365
assertEquals (expected , queryString , false );
364
366
}
367
+
368
+ @ Test // #1753
369
+ @ DisplayName ("should map names and value in nested entities with sub-fields" )
370
+ void shouldMapNamesAndValueInNestedEntitiesWithSubfields () throws JSONException {
371
+
372
+ String expected = "{\n " + //
373
+ " \" bool\" : {\n " + //
374
+ " \" must\" : [\n " + //
375
+ " {\n " + //
376
+ " \" nested\" : {\n " + //
377
+ " \" query\" : {\n " + //
378
+ " \" query_string\" : {\n " + //
379
+ " \" query\" : \" Foobar\" ,\n " + //
380
+ " \" fields\" : [\n " + //
381
+ " \" per-sons.nick-name.keyword^1.0\" \n " + //
382
+ " ]\n " + //
383
+ " }\n " + //
384
+ " },\n " + //
385
+ " \" path\" : \" per-sons\" \n " + //
386
+ " }\n " + //
387
+ " }\n " + //
388
+ " ]\n " + //
389
+ " }\n " + //
390
+ "}\n " ; //
391
+
392
+ CriteriaQuery criteriaQuery = new CriteriaQuery (
393
+ new Criteria ("persons.nickName.keyword" ).is ("Foobar" )
394
+ );
395
+ mappingElasticsearchConverter .updateQuery (criteriaQuery , House .class );
396
+ String queryString = new CriteriaQueryProcessor ().createQuery (criteriaQuery .getCriteria ()).toString ();
397
+
398
+ assertEquals (expected , queryString , false );
399
+ }
365
400
// endregion
366
401
367
402
// region helper functions
@@ -379,6 +414,7 @@ static class Person {
379
414
@ Nullable @ Id String id ;
380
415
@ Nullable @ Field (name = "first-name" ) String firstName ;
381
416
@ Nullable @ Field (name = "last-name" ) String lastName ;
417
+ @ Nullable @ MultiField (mainField = @ Field (name ="nick-name" ), otherFields = {@ InnerField (suffix = "keyword" , type = FieldType .Keyword )}) String nickName ;
382
418
@ Nullable @ Field (name = "created-date" , type = FieldType .Date , format = DateFormat .epoch_millis ) Date createdDate ;
383
419
@ Nullable @ Field (name = "birth-date" , type = FieldType .Date , format = {},
384
420
pattern = "dd.MM.uuuu" ) LocalDate birthDate ;
0 commit comments