parent
3a24fe9d37
commit
10e0e59561
|
@ -78,7 +78,7 @@ public abstract class GeoGridAggregatorTestCase<T extends InternalGeoGridBucket>
|
|||
});
|
||||
}
|
||||
|
||||
public void testFieldMissing() throws IOException {
|
||||
public void testUnmapped() throws IOException {
|
||||
testCase(new MatchAllDocsQuery(), "wrong_field", randomPrecision(), null, geoGrid -> {
|
||||
assertEquals(0, geoGrid.getBuckets().size());
|
||||
}, iw -> {
|
||||
|
@ -86,6 +86,15 @@ public abstract class GeoGridAggregatorTestCase<T extends InternalGeoGridBucket>
|
|||
});
|
||||
}
|
||||
|
||||
public void testUnmappedMissing() throws IOException {
|
||||
GeoGridAggregationBuilder builder = createBuilder("_name")
|
||||
.field("wrong_field")
|
||||
.missing("53.69437,6.475031");
|
||||
testCase(new MatchAllDocsQuery(), randomPrecision(), null, geoGrid -> assertEquals(1, geoGrid.getBuckets().size()),
|
||||
iw -> iw.addDocument(Collections.singleton(new LatLonDocValuesField(FIELD_NAME, 10D, 10D))), builder);
|
||||
|
||||
}
|
||||
|
||||
public void testWithSeveralDocs() throws IOException {
|
||||
int precision = randomPrecision();
|
||||
int numPoints = randomIntBetween(8, 128);
|
||||
|
@ -197,6 +206,13 @@ public abstract class GeoGridAggregatorTestCase<T extends InternalGeoGridBucket>
|
|||
private void testCase(Query query, String field, int precision, GeoBoundingBox geoBoundingBox,
|
||||
Consumer<InternalGeoGrid<T>> verify,
|
||||
CheckedConsumer<RandomIndexWriter, IOException> buildIndex) throws IOException {
|
||||
testCase(query, precision, geoBoundingBox, verify, buildIndex, createBuilder("_name").field(field));
|
||||
}
|
||||
|
||||
private void testCase(Query query, int precision, GeoBoundingBox geoBoundingBox,
|
||||
Consumer<InternalGeoGrid<T>> verify,
|
||||
CheckedConsumer<RandomIndexWriter, IOException> buildIndex,
|
||||
GeoGridAggregationBuilder aggregationBuilder) throws IOException {
|
||||
Directory directory = newDirectory();
|
||||
RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory);
|
||||
buildIndex.accept(indexWriter);
|
||||
|
@ -205,7 +221,6 @@ public abstract class GeoGridAggregatorTestCase<T extends InternalGeoGridBucket>
|
|||
IndexReader indexReader = DirectoryReader.open(directory);
|
||||
IndexSearcher indexSearcher = newSearcher(indexReader, true, true);
|
||||
|
||||
GeoGridAggregationBuilder aggregationBuilder = createBuilder("_name").field(field);
|
||||
aggregationBuilder.precision(precision);
|
||||
if (geoBoundingBox != null) {
|
||||
aggregationBuilder.setGeoBoundingBox(geoBoundingBox);
|
||||
|
|
|
@ -219,6 +219,17 @@ public class AutoDateHistogramAggregatorTests extends AggregatorTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public void testUnmappedMissing() throws IOException {
|
||||
testBothCases(DEFAULT_QUERY, DATES_WITH_TIME,
|
||||
aggregation -> aggregation.setNumBuckets(10).field("wrong_field").missing("2017-12-12"),
|
||||
histogram -> {
|
||||
assertEquals(1, histogram.getBuckets().size());
|
||||
assertTrue(AggregationInspectionHelper.hasValue(histogram));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public void testIntervalYear() throws IOException {
|
||||
|
||||
|
||||
|
|
|
@ -84,6 +84,30 @@ public class GeoCentroidAggregatorTests extends AggregatorTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void testUnmappedWithMissing() throws Exception {
|
||||
try (Directory dir = newDirectory();
|
||||
RandomIndexWriter w = new RandomIndexWriter(random(), dir)) {
|
||||
GeoCentroidAggregationBuilder aggBuilder = new GeoCentroidAggregationBuilder("my_agg")
|
||||
.field("another_field")
|
||||
.missing("53.69437,6.475031");
|
||||
|
||||
GeoPoint expectedCentroid = new GeoPoint(53.69437, 6.475031);
|
||||
Document document = new Document();
|
||||
document.add(new LatLonDocValuesField("field", 10, 10));
|
||||
w.addDocument(document);
|
||||
try (IndexReader reader = w.getReader()) {
|
||||
IndexSearcher searcher = new IndexSearcher(reader);
|
||||
|
||||
MappedFieldType fieldType = new GeoPointFieldMapper.GeoPointFieldType();
|
||||
fieldType.setHasDocValues(true);
|
||||
fieldType.setName("another_field");
|
||||
InternalGeoCentroid result = search(searcher, new MatchAllDocsQuery(), aggBuilder, fieldType);
|
||||
assertEquals(result.centroid(), expectedCentroid);
|
||||
assertTrue(AggregationInspectionHelper.hasValue(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testSingleValuedField() throws Exception {
|
||||
int numDocs = scaledRandomIntBetween(64, 256);
|
||||
int numUniqueGeoPoints = randomIntBetween(1, numDocs);
|
||||
|
|
Loading…
Reference in New Issue