Skip to content

Commit

Permalink
Added integrationTest check if MultiTermsAggregation is supported
Browse files Browse the repository at this point in the history
Signed-off-by: Fabian Kopatschek <[email protected]>
  • Loading branch information
fabiankopatschek committed Sep 22, 2023
1 parent 4eb9510 commit 5095e55
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.opensearch.client.opensearch.integTest;

import org.junit.Test;
import org.opensearch.Version;
import org.opensearch.client.opensearch._types.Refresh;
import org.opensearch.client.opensearch._types.aggregations.Aggregation;
import org.opensearch.client.opensearch._types.aggregations.AggregationRange;
Expand All @@ -19,6 +20,7 @@
import org.opensearch.client.opensearch._types.aggregations.MultiTermsAggregation;
import org.opensearch.client.opensearch._types.aggregations.RangeAggregation;
import org.opensearch.client.opensearch._types.mapping.Property;
import org.opensearch.client.opensearch.core.InfoResponse;
import org.opensearch.client.opensearch.core.SearchResponse;

import java.io.IOException;
Expand Down Expand Up @@ -67,6 +69,8 @@ public void testDateRangeAggregation() throws Exception {

@Test
public void testMultiTermsAggregation() throws Exception {
checkIfOpenSearchSupportsMultiTermsAggregation();

var index = "test-multiterms-aggregation-no-size";
createMultiTermsDocuments(index);
var searchResponse = sendAggregateRequest(index, "multiterms", getMultiTermsAggregation(null));
Expand All @@ -83,6 +87,8 @@ public void testMultiTermsAggregation() throws Exception {

@Test
public void testMultiTermsAggregationWithSizeFewerThenBucketsSize() throws Exception {
checkIfOpenSearchSupportsMultiTermsAggregation();

var index = "test-multiterms-aggregation-fewer-size";
createMultiTermsDocuments(index);
var searchResponse = sendAggregateRequest(index, "multiterms", getMultiTermsAggregation(1));
Expand All @@ -99,6 +105,8 @@ public void testMultiTermsAggregationWithSizeFewerThenBucketsSize() throws Excep

@Test
public void testMultiTermsAggregationWithSizeBiggerThenBucketsSize() throws Exception {
checkIfOpenSearchSupportsMultiTermsAggregation();

var index = "test-multiterms-aggregation-bigger-size";
createMultiTermsDocuments(index);
var searchResponse = sendAggregateRequest(index, "multiterms", getMultiTermsAggregation(50));
Expand All @@ -113,6 +121,16 @@ public void testMultiTermsAggregationWithSizeBiggerThenBucketsSize() throws Exce
assertEquals(1, buckets.get(0).docCount());
}

private void checkIfOpenSearchSupportsMultiTermsAggregation() throws Exception {
InfoResponse info = javaClient().info();
String version = info.version().number();
if (version.contains("SNAPSHOT")) {
version = version.split("-")[0];
}
assumeTrue("multi_terms is supported in OpenSearch 2.1.0 and later",
Version.fromString(version).onOrAfter(Version.fromString("2.1.0")));
}

private Aggregation getExpiryDateRangeAggregation() {
DateRangeAggregation expiryDateRangeAggregation = new DateRangeAggregation.Builder()
.field("expDate")
Expand Down

0 comments on commit 5095e55

Please sign in to comment.