|
50 | 50 | import org.elasticsearch.common.lucene.search.function.CombineFunction;
|
51 | 51 | import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery;
|
52 | 52 | import org.elasticsearch.index.VersionType;
|
| 53 | +import org.elasticsearch.index.query.InnerHitBuilder; |
53 | 54 | import org.elasticsearch.index.query.QueryBuilders;
|
54 | 55 | import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
|
55 | 56 | import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder;
|
56 | 57 | import org.elasticsearch.index.query.functionscore.GaussDecayFunctionBuilder;
|
| 58 | +import org.elasticsearch.join.query.HasChildQueryBuilder; |
| 59 | +import org.elasticsearch.join.query.JoinQueryBuilders; |
57 | 60 | import org.elasticsearch.join.query.ParentIdQueryBuilder;
|
58 | 61 | import org.elasticsearch.script.Script;
|
59 | 62 | import org.elasticsearch.script.ScriptType;
|
@@ -3029,6 +3032,46 @@ public void shouldAddAliasWithGivenRoutingValue() {
|
3029 | 3032 | indexOperations.removeAlias(aliasQuery);
|
3030 | 3033 | }
|
3031 | 3034 |
|
| 3035 | + @Test // #1997 |
| 3036 | + @DisplayName("should return document with inner hits size zero") |
| 3037 | + void shouldReturnDocumentWithInnerHitsSizeZero() { |
| 3038 | + |
| 3039 | + // given |
| 3040 | + SampleJoinEntity sampleQuestionEntity1 = new SampleJoinEntity(); |
| 3041 | + sampleQuestionEntity1.setUuid("q1"); |
| 3042 | + sampleQuestionEntity1.setText("This is a question"); |
| 3043 | + sampleQuestionEntity1.setMyJoinField(new JoinField<>("question")); |
| 3044 | + |
| 3045 | + SampleJoinEntity sampleAnswerEntity1 = new SampleJoinEntity(); |
| 3046 | + sampleAnswerEntity1.setUuid("a1"); |
| 3047 | + sampleAnswerEntity1.setText("This is an answer"); |
| 3048 | + sampleAnswerEntity1.setMyJoinField(new JoinField<>("answer", sampleQuestionEntity1.getUuid())); |
| 3049 | + |
| 3050 | + SampleJoinEntity sampleAnswerEntity2 = new SampleJoinEntity(); |
| 3051 | + sampleAnswerEntity1.setUuid("a2"); |
| 3052 | + sampleAnswerEntity1.setText("This is an answer"); |
| 3053 | + sampleAnswerEntity1.setMyJoinField(new JoinField<>("answer", sampleQuestionEntity1.getUuid())); |
| 3054 | + |
| 3055 | + IndexOperations indexOps = operations.indexOps(SampleJoinEntity.class); |
| 3056 | + operations.save(Arrays.asList(sampleQuestionEntity1, sampleAnswerEntity1, sampleAnswerEntity2)); |
| 3057 | + indexOps.refresh(); |
| 3058 | + |
| 3059 | + // when |
| 3060 | + Query query = new NativeSearchQueryBuilder().withQuery( |
| 3061 | + JoinQueryBuilders.hasChildQuery("answer", matchAllQuery(), org.apache.lucene.search.join.ScoreMode.Avg) |
| 3062 | + .innerHit(new InnerHitBuilder("innerHits").setSize(0))) |
| 3063 | + .build(); |
| 3064 | + |
| 3065 | + SearchHits<SampleJoinEntity> searchHits = operations.search(query, SampleJoinEntity.class); |
| 3066 | + |
| 3067 | + // then |
| 3068 | + assertThat(searchHits).isNotNull(); |
| 3069 | + assertThat(searchHits.getTotalHits()).isEqualTo(1); |
| 3070 | + assertThat(searchHits.getSearchHits()).hasSize(1); |
| 3071 | + assertThat(searchHits.getSearchHit(0).getInnerHits().size()).isEqualTo(1); |
| 3072 | + assertThat(searchHits.getSearchHit(0).getInnerHits("innerHits").getTotalHits()).isEqualTo(1); |
| 3073 | + } |
| 3074 | + |
3032 | 3075 | @Test // DATAES-541
|
3033 | 3076 | public void shouldRemoveAlias() {
|
3034 | 3077 |
|
|
0 commit comments