|
40 | 40 | import org.opensearch.core.common.io.stream.InputStreamStreamInput;
|
41 | 41 | import org.opensearch.core.common.io.stream.OutputStreamStreamOutput;
|
42 | 42 | import org.opensearch.index.query.QueryBuilders;
|
| 43 | +import org.opensearch.index.query.TermsQueryBuilder; |
| 44 | +import org.opensearch.indices.TermsLookup; |
43 | 45 | import org.opensearch.test.OpenSearchIntegTestCase;
|
44 | 46 |
|
45 | 47 | import java.io.ByteArrayInputStream;
|
|
52 | 54 | import java.util.Set;
|
53 | 55 |
|
54 | 56 | import static java.util.Collections.singleton;
|
| 57 | +import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS; |
55 | 58 | import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder;
|
56 | 59 | import static org.opensearch.index.query.QueryBuilders.queryStringQuery;
|
57 | 60 | import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
|
@@ -305,4 +308,22 @@ public void testStreamExplain() throws Exception {
|
305 | 308 | result = Lucene.readExplanation(esBuffer);
|
306 | 309 | assertThat(exp.toString(), equalTo(result.toString()));
|
307 | 310 | }
|
| 311 | + |
| 312 | + public void testQueryRewrite() { |
| 313 | + client().admin() |
| 314 | + .indices() |
| 315 | + .prepareCreate("twitter") |
| 316 | + .setMapping("user", "type=integer", "followers", "type=integer") |
| 317 | + .setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 2).put("index.number_of_routing_shards", 2)) |
| 318 | + .get(); |
| 319 | + client().prepareIndex("twitter").setId("1").setSource("followers", new int[] { 1, 2, 3 }).get(); |
| 320 | + refresh(); |
| 321 | + |
| 322 | + TermsQueryBuilder termsLookupQuery = QueryBuilders.termsLookupQuery("user", new TermsLookup("twitter", "1", "followers")); |
| 323 | + ExplainResponse response = client().prepareExplain("twitter", "1").setQuery(termsLookupQuery).get(); |
| 324 | + |
| 325 | + Explanation explanation = response.getExplanation(); |
| 326 | + assertNotNull(explanation); |
| 327 | + assertTrue(explanation.isMatch()); |
| 328 | + } |
308 | 329 | }
|
0 commit comments