Skip to content

Modify unsigned_long tests for broader ranges #63782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.RangeQueryBuilder;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
Expand All @@ -38,6 +39,7 @@
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse;
import static org.hamcrest.Matchers.containsString;
import static org.elasticsearch.search.aggregations.AggregationBuilders.terms;
import static org.hamcrest.Matchers.equalTo;

@ESIntegTestCase.SuiteScopeTestCase

Expand Down Expand Up @@ -227,13 +229,13 @@ public void testAggs() {
{
SearchResponse response = client().prepareSearch("idx")
.setSize(0)
.addAggregation(histogram("ul_histo").field("ul_field").interval(9.223372036854776E18).minDocCount(0))
.addAggregation(histogram("ul_histo").field("ul_field").interval(9E18).minDocCount(0))
.get();
assertSearchResponse(response);
Histogram histo = response.getAggregations().get("ul_histo");

long[] expectedBucketDocCounts = { 3, 3, 4 };
double[] expectedBucketKeys = { 0, 9.223372036854776E18, 1.8446744073709552E19 };
double[] expectedBucketKeys = { 0, 9.0E18, 1.8E19 };
int i = 0;
for (Histogram.Bucket bucket : histo.getBuckets()) {
assertEquals(expectedBucketDocCounts[i], bucket.getDocCount());
Expand All @@ -247,20 +249,14 @@ public void testAggs() {
SearchResponse response = client().prepareSearch("idx")
.setSize(0)
.addAggregation(
range("ul_range").field("ul_field")
.addUnboundedTo(9.223372036854776E18)
.addRange(9.223372036854776E18, 1.8446744073709552E19)
.addUnboundedFrom(1.8446744073709552E19)
range("ul_range").field("ul_field").addUnboundedTo(9.0E18).addRange(9.0E18, 1.8E19).addUnboundedFrom(1.8E19)
)
.get();
assertSearchResponse(response);
Range range = response.getAggregations().get("ul_range");

long[] expectedBucketDocCounts = { 3, 3, 4 };
String[] expectedBucketKeys = {
"*-9.223372036854776E18",
"9.223372036854776E18-1.8446744073709552E19",
"1.8446744073709552E19-*" };
String[] expectedBucketKeys = { "*-9.0E18", "9.0E18-1.8E19", "1.8E19-*" };
int i = 0;
for (Range.Bucket bucket : range.getBuckets()) {
assertEquals(expectedBucketDocCounts[i], bucket.getDocCount());
Expand Down Expand Up @@ -293,4 +289,19 @@ public void testSortDifferentFormatsShouldFail() {
"Can't do sort across indices, as a field has [unsigned_long] type in one index, and different type in another index!"
);
}

public void testRangeQuery() {
SearchResponse response = client().prepareSearch("idx")
.setSize(0)
.setQuery(new RangeQueryBuilder("ul_field").to("9.0E18").includeUpper(false))
.get();
assertThat(response.getHits().getTotalHits().value, equalTo(3L));
response = client().prepareSearch("idx")
.setSize(0)
.setQuery(new RangeQueryBuilder("ul_field").from("9.0E18").to("1.8E19").includeUpper(false))
.get();
assertThat(response.getHits().getTotalHits().value, equalTo(3L));
response = client().prepareSearch("idx").setSize(0).setQuery(new RangeQueryBuilder("ul_field").from("1.8E19")).get();
assertThat(response.getHits().getTotalHits().value, equalTo(4L));
}
}