|
53 | 53 | import org.elasticsearch.action.update.UpdateRequest;
|
54 | 54 | import org.elasticsearch.cluster.metadata.AliasMetadata;
|
55 | 55 | import org.elasticsearch.index.VersionType;
|
| 56 | +import org.elasticsearch.index.query.InnerHitBuilder; |
| 57 | +import org.elasticsearch.index.query.QueryBuilders; |
| 58 | +import org.elasticsearch.join.query.HasChildQueryBuilder; |
| 59 | +import org.elasticsearch.join.query.JoinQueryBuilders; |
56 | 60 | import org.elasticsearch.join.query.ParentIdQueryBuilder;
|
57 | 61 | import org.elasticsearch.script.Script;
|
58 | 62 | import org.elasticsearch.script.ScriptType;
|
@@ -2988,6 +2992,46 @@ public void shouldAddAliasWithGivenRoutingValue() {
|
2988 | 2992 | indexOperations.removeAlias(aliasQuery);
|
2989 | 2993 | }
|
2990 | 2994 |
|
| 2995 | + @Test // #1997 |
| 2996 | + @DisplayName("should return document with inner hits size zero") |
| 2997 | + void shouldReturnDocumentWithInnerHitsSizeZero() { |
| 2998 | + |
| 2999 | + // given |
| 3000 | + SampleJoinEntity sampleQuestionEntity1 = new SampleJoinEntity(); |
| 3001 | + sampleQuestionEntity1.setUuid("q1"); |
| 3002 | + sampleQuestionEntity1.setText("This is a question"); |
| 3003 | + sampleQuestionEntity1.setMyJoinField(new JoinField<>("question")); |
| 3004 | + |
| 3005 | + SampleJoinEntity sampleAnswerEntity1 = new SampleJoinEntity(); |
| 3006 | + sampleAnswerEntity1.setUuid("a1"); |
| 3007 | + sampleAnswerEntity1.setText("This is an answer"); |
| 3008 | + sampleAnswerEntity1.setMyJoinField(new JoinField<>("answer", sampleQuestionEntity1.getUuid())); |
| 3009 | + |
| 3010 | + SampleJoinEntity sampleAnswerEntity2 = new SampleJoinEntity(); |
| 3011 | + sampleAnswerEntity1.setUuid("a2"); |
| 3012 | + sampleAnswerEntity1.setText("This is an answer"); |
| 3013 | + sampleAnswerEntity1.setMyJoinField(new JoinField<>("answer", sampleQuestionEntity1.getUuid())); |
| 3014 | + |
| 3015 | + IndexOperations indexOps = operations.indexOps(SampleJoinEntity.class); |
| 3016 | + operations.save(Arrays.asList(sampleQuestionEntity1, sampleAnswerEntity1, sampleAnswerEntity2)); |
| 3017 | + indexOps.refresh(); |
| 3018 | + |
| 3019 | + // when |
| 3020 | + Query query = new NativeSearchQueryBuilder().withQuery( |
| 3021 | + JoinQueryBuilders.hasChildQuery("answer", matchAllQuery(), org.apache.lucene.search.join.ScoreMode.Avg) |
| 3022 | + .innerHit(new InnerHitBuilder("innerHits").setSize(0))) |
| 3023 | + .build(); |
| 3024 | + |
| 3025 | + SearchHits<SampleJoinEntity> searchHits = operations.search(query, SampleJoinEntity.class); |
| 3026 | + |
| 3027 | + // then |
| 3028 | + assertThat(searchHits).isNotNull(); |
| 3029 | + assertThat(searchHits.getTotalHits()).isEqualTo(1); |
| 3030 | + assertThat(searchHits.getSearchHits()).hasSize(1); |
| 3031 | + assertThat(searchHits.getSearchHit(0).getInnerHits().size()).isEqualTo(1); |
| 3032 | + assertThat(searchHits.getSearchHit(0).getInnerHits("innerHits").getTotalHits()).isEqualTo(1); |
| 3033 | + } |
| 3034 | + |
2991 | 3035 | @Test // DATAES-541
|
2992 | 3036 | public void shouldRemoveAlias() {
|
2993 | 3037 |
|
|
0 commit comments