use of org.opensearch.index.query.QueryShardContext in project OpenSearch by opensearch-project.
the class HasChildQueryBuilderTests method testNonDefaultSimilarity.
public void testNonDefaultSimilarity() throws Exception {
QueryShardContext shardContext = createShardContext();
HasChildQueryBuilder hasChildQueryBuilder = hasChildQuery(CHILD_DOC, new TermQueryBuilder("custom_string", "value"), ScoreMode.None);
HasChildQueryBuilder.LateParsingQuery query = (HasChildQueryBuilder.LateParsingQuery) hasChildQueryBuilder.toQuery(shardContext);
Similarity expected = SimilarityService.BUILT_IN.get(similarity).apply(Settings.EMPTY, Version.CURRENT, null);
assertThat(((PerFieldSimilarityWrapper) query.getSimilarity()).get("custom_string"), instanceOf(expected.getClass()));
}
use of org.opensearch.index.query.QueryShardContext in project OpenSearch by opensearch-project.
the class ParentIdQueryBuilderTests method testDisallowExpensiveQueries.
public void testDisallowExpensiveQueries() {
QueryShardContext queryShardContext = mock(QueryShardContext.class);
when(queryShardContext.allowExpensiveQueries()).thenReturn(false);
ParentIdQueryBuilder queryBuilder = doCreateTestQueryBuilder();
OpenSearchException e = expectThrows(OpenSearchException.class, () -> queryBuilder.toQuery(queryShardContext));
assertEquals("[joining] queries cannot be executed when 'search.allow_expensive_queries' is set to false.", e.getMessage());
}
use of org.opensearch.index.query.QueryShardContext in project OpenSearch by opensearch-project.
the class HasChildQueryBuilderTests method testDisallowExpensiveQueries.
public void testDisallowExpensiveQueries() {
QueryShardContext queryShardContext = mock(QueryShardContext.class);
when(queryShardContext.allowExpensiveQueries()).thenReturn(false);
HasChildQueryBuilder queryBuilder = hasChildQuery(CHILD_DOC, new TermQueryBuilder("custom_string", "value"), ScoreMode.None);
OpenSearchException e = expectThrows(OpenSearchException.class, () -> queryBuilder.toQuery(queryShardContext));
assertEquals("[joining] queries cannot be executed when 'search.allow_expensive_queries' is set to false.", e.getMessage());
}
use of org.opensearch.index.query.QueryShardContext in project OpenSearch by opensearch-project.
the class HasParentQueryBuilderTests method testIgnoreUnmappedWithRewrite.
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));
}
use of org.opensearch.index.query.QueryShardContext in project OpenSearch by opensearch-project.
the class HasParentQueryBuilderTests method testToQueryInnerQueryType.
public void testToQueryInnerQueryType() throws IOException {
QueryShardContext shardContext = createShardContext();
HasParentQueryBuilder hasParentQueryBuilder = new HasParentQueryBuilder(PARENT_DOC, new IdsQueryBuilder().addIds("id"), false);
Query query = hasParentQueryBuilder.toQuery(shardContext);
HasChildQueryBuilderTests.assertLateParsingQuery(query, PARENT_DOC, "id");
}
Aggregations