Don't ignore `ignore_unmapped` options on nested, has_child and has_parent queries if the wrapped query gets rewritten.
This commit is contained in:
parent
b04f8fe159
commit
cb8f8fc9ad
|
@ -473,7 +473,10 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
|
|||
QueryBuilder rewrittenQuery = query.rewrite(queryRewriteContext);
|
||||
if (rewrittenQuery != query) {
|
||||
InnerHitBuilder rewrittenInnerHit = InnerHitBuilder.rewrite(innerHitBuilder, rewrittenQuery);
|
||||
return new HasChildQueryBuilder(type, rewrittenQuery, minChildren, maxChildren, scoreMode, rewrittenInnerHit);
|
||||
HasChildQueryBuilder hasChildQueryBuilder =
|
||||
new HasChildQueryBuilder(type, rewrittenQuery, minChildren, maxChildren, scoreMode, rewrittenInnerHit);
|
||||
hasChildQueryBuilder.ignoreUnmapped(ignoreUnmapped);
|
||||
return hasChildQueryBuilder;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -305,7 +305,9 @@ public class HasParentQueryBuilder extends AbstractQueryBuilder<HasParentQueryBu
|
|||
QueryBuilder rewrittenQuery = query.rewrite(queryShardContext);
|
||||
if (rewrittenQuery != query) {
|
||||
InnerHitBuilder rewrittenInnerHit = InnerHitBuilder.rewrite(innerHit, rewrittenQuery);
|
||||
return new HasParentQueryBuilder(type, rewrittenQuery, score, rewrittenInnerHit);
|
||||
HasParentQueryBuilder hasParentQueryBuilder = new HasParentQueryBuilder(type, rewrittenQuery, score, rewrittenInnerHit);
|
||||
hasParentQueryBuilder.ignoreUnmapped(ignoreUnmapped);
|
||||
return hasParentQueryBuilder;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -255,7 +255,9 @@ public class NestedQueryBuilder extends AbstractQueryBuilder<NestedQueryBuilder>
|
|||
QueryBuilder rewrittenQuery = query.rewrite(queryRewriteContext);
|
||||
if (rewrittenQuery != query) {
|
||||
InnerHitBuilder rewrittenInnerHit = InnerHitBuilder.rewrite(innerHitBuilder, rewrittenQuery);
|
||||
return new NestedQueryBuilder(path, rewrittenQuery, scoreMode, rewrittenInnerHit);
|
||||
NestedQueryBuilder nestedQuery = new NestedQueryBuilder(path, rewrittenQuery, scoreMode, rewrittenInnerHit);
|
||||
nestedQuery.ignoreUnmapped(ignoreUnmapped);
|
||||
return nestedQuery;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -331,4 +331,15 @@ public class HasChildQueryBuilderTests extends AbstractQueryTestCase<HasChildQue
|
|||
QueryShardException e = expectThrows(QueryShardException.class, () -> failingQueryBuilder.toQuery(createShardContext()));
|
||||
assertThat(e.getMessage(), containsString("[" + HasChildQueryBuilder.NAME + "] no mapping found for type [unmapped]"));
|
||||
}
|
||||
|
||||
public void testIgnoreUnmappedWithRewrite() throws IOException {
|
||||
// WrapperQueryBuilder makes sure we always rewrite
|
||||
final HasChildQueryBuilder queryBuilder
|
||||
= new HasChildQueryBuilder("unmapped", new WrapperQueryBuilder(new MatchAllQueryBuilder().toString()), ScoreMode.None);
|
||||
queryBuilder.ignoreUnmapped(true);
|
||||
QueryShardContext queryShardContext = createShardContext();
|
||||
Query query = queryBuilder.rewrite(queryShardContext).toQuery(queryShardContext);
|
||||
assertThat(query, notNullValue());
|
||||
assertThat(query, instanceOf(MatchNoDocsQuery.class));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -213,4 +213,15 @@ public class HasParentQueryBuilderTests extends AbstractQueryTestCase<HasParentQ
|
|||
assertThat(e.getMessage(),
|
||||
containsString("[" + HasParentQueryBuilder.NAME + "] query configured 'parent_type' [unmapped] is not a valid type"));
|
||||
}
|
||||
|
||||
public void testIgnoreUnmappedWithRewrite() throws IOException {
|
||||
// WrapperQueryBuilder makes sure we always rewrite
|
||||
final HasParentQueryBuilder queryBuilder =
|
||||
new HasParentQueryBuilder("unmapped", new WrapperQueryBuilder(new MatchAllQueryBuilder().toString()), false);
|
||||
queryBuilder.ignoreUnmapped(true);
|
||||
QueryShardContext queryShardContext = createShardContext();
|
||||
Query query = queryBuilder.rewrite(queryShardContext).toQuery(queryShardContext);
|
||||
assertThat(query, notNullValue());
|
||||
assertThat(query, instanceOf(MatchNoDocsQuery.class));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.elasticsearch.index.query;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.generators.RandomPicks;
|
||||
|
||||
import org.apache.lucene.search.MatchNoDocsQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.join.ScoreMode;
|
||||
|
@ -194,4 +193,15 @@ public class NestedQueryBuilderTests extends AbstractQueryTestCase<NestedQueryBu
|
|||
IllegalStateException e = expectThrows(IllegalStateException.class, () -> failingQueryBuilder.toQuery(createShardContext()));
|
||||
assertThat(e.getMessage(), containsString("[" + NestedQueryBuilder.NAME + "] failed to find nested object under path [unmapped]"));
|
||||
}
|
||||
|
||||
public void testIgnoreUnmappedWithRewrite() throws IOException {
|
||||
// WrapperQueryBuilder makes sure we always rewrite
|
||||
final NestedQueryBuilder queryBuilder =
|
||||
new NestedQueryBuilder("unmapped", new WrapperQueryBuilder(new MatchAllQueryBuilder().toString()), ScoreMode.None);
|
||||
queryBuilder.ignoreUnmapped(true);
|
||||
QueryShardContext queryShardContext = createShardContext();
|
||||
Query query = queryBuilder.rewrite(queryShardContext).toQuery(queryShardContext);
|
||||
assertThat(query, notNullValue());
|
||||
assertThat(query, instanceOf(MatchNoDocsQuery.class));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue