|
14 | 14 | import org.opensearch.common.xcontent.XContentFactory; |
15 | 15 | import org.opensearch.core.xcontent.XContentBuilder; |
16 | 16 | import org.opensearch.index.query.QueryBuilders; |
| 17 | +import org.opensearch.index.query.TermsQueryBuilder; |
17 | 18 | import org.opensearch.test.OpenSearchSingleNodeTestCase; |
18 | 19 | import org.hamcrest.MatcherAssert; |
19 | 20 |
|
20 | 21 | import java.io.IOException; |
21 | 22 | import java.net.InetAddress; |
22 | 23 | import java.util.ArrayList; |
| 24 | +import java.util.Collection; |
23 | 25 | import java.util.List; |
24 | 26 | import java.util.Map; |
25 | 27 | import java.util.Objects; |
@@ -90,8 +92,19 @@ public void testMassive() throws Exception { |
90 | 92 | } |
91 | 93 |
|
92 | 94 | bulkRequestBuilder.setRefreshPolicy(IMMEDIATE).get(); |
93 | | - SearchResponse result = client().prepareSearch(defaultIndexName).setQuery(QueryBuilders.termsQuery("addr", toQuery)).get(); |
94 | | - MatcherAssert.assertThat(Objects.requireNonNull(result.getHits().getTotalHits()).value, equalTo((long) cidrs + ips + addMatches)); |
| 95 | + long expectedMatches = (long) cidrs + ips + addMatches; |
| 96 | + for (String field : List.of("addr", "addr.idx", "addr.dv")) { |
| 97 | + assertTermsHitCount(field, toQuery, expectedMatches); |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + private void assertTermsHitCount(String field, Collection<String> toQuery, long expectedMatches) { |
| 102 | + TermsQueryBuilder ipTerms = QueryBuilders.termsQuery(field, new ArrayList<>(toQuery)); |
| 103 | + SearchResponse result = client().prepareSearch(defaultIndexName) |
| 104 | + .setQuery(QueryBuilders.boolQuery().must(ipTerms).filter(QueryBuilders.termsQuery("dummy_filter", "a", "b"))) |
| 105 | + .get(); |
| 106 | + long hitsFound = Objects.requireNonNull(result.getHits().getTotalHits()).value; |
| 107 | + MatcherAssert.assertThat(field, hitsFound, equalTo(expectedMatches)); |
95 | 108 | } |
96 | 109 |
|
97 | 110 | // Converts an IP string (either IPv4 or IPv6) to a byte array |
@@ -169,6 +182,9 @@ private XContentBuilder createMapping() throws IOException { |
169 | 182 | .endObject() |
170 | 183 | .endObject() |
171 | 184 | .endObject() |
| 185 | + .startObject("dummy_filter") |
| 186 | + .field("type", "keyword") |
| 187 | + .endObject() |
172 | 188 | .endObject() |
173 | 189 | .endObject(); |
174 | 190 | } |
|
0 commit comments