Skip to content
Closed
Show file tree
Hide file tree
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 @@ -302,11 +302,6 @@ private NumberFieldMapper.NumberFieldType delegateFieldType() {
return delegateFieldType(defaultMetric);
}

@Override
public String familyTypeName() {
return NumberFieldMapper.NumberType.DOUBLE.typeName();
}

@Override
public String typeName() {
return CONTENT_TYPE;
Expand Down Expand Up @@ -497,18 +492,7 @@ public BucketedSort newBucketedSort(

@Override
public ValueFetcher valueFetcher(SearchExecutionContext context, String format) {
if (format != null) {
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats.");
}

return new SourceValueFetcher(name(), context) {
@Override
@SuppressWarnings("unchecked")
protected Object parseSourceValue(Object value) {
Map<String, Double> metrics = (Map<String, Double>) value;
return metrics.get(defaultMetric.name());
}
};
return SourceValueFetcher.identity(name(), context, format);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ public void testNoSubFieldsIterated() throws IOException {
public void testFieldCaps() throws IOException {
MapperService aggMetricMapperService = createMapperService(fieldMapping(this::minimalMapping));
MappedFieldType fieldType = aggMetricMapperService.fieldType("field");
assertThat(fieldType.familyTypeName(), equalTo("double"));
assertThat(fieldType.familyTypeName(), equalTo("aggregate_metric_double"));
assertTrue(fieldType.isSearchable());
assertTrue(fieldType.isAggregatable());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,17 @@ public void testRangeQuery() {

public void testFetchSourceValueWithOneMetric() throws IOException {
final MappedFieldType fieldType = createDefaultFieldType("field", Collections.emptyMap(), Metric.min);
final double defaultValue = 45.8;
final Map<String, Object> metric = Collections.singletonMap("min", defaultValue);
assertEquals(List.of(defaultValue), fetchSourceValue(fieldType, metric));
final double min = 45.8;
final Map<String, Object> metric = Collections.singletonMap("min", min);
assertEquals(List.of(metric), fetchSourceValue(fieldType, metric));
}

public void testFetchSourceValueWithMultipleMetrics() throws IOException {
final MappedFieldType fieldType = createDefaultFieldType("field", Collections.emptyMap(), Metric.max);
final double defaultValue = 45.8;
final Map<String, Object> metric = Map.of("min", 14.2, "max", defaultValue);
assertEquals(List.of(defaultValue), fetchSourceValue(fieldType, metric));
final double max = 45.8;
final double min = 14.2;
final Map<String, Object> metric = Map.of("min", min, "max", max);
assertEquals(List.of(metric), fetchSourceValue(fieldType, metric));
}

/** Tests that aggregate_metric_double uses the default_metric subfield's doc-values as values in scripts */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,63 @@
index: test
body:
sort: [ { metric.min: desc } ]

---
"Test fields api":
- skip:
version: "- 8.3.99"
reason: "Breaking change introduced in 8.4.0"
- do:
indices.create:
index: test
body:
mappings:
properties:
metric:
type: aggregate_metric_double
metrics: [min, max, sum, value_count]
default_metric: sum

- do:
index:
index: test
id: "1"
body:
metric:
min: 10
max: 100
sum: 200
value_count: 5
refresh: true

- do:
index:
index: test
id: "2"
body:
metric:
min: 50
max: 1000
sum: 5000
value_count: 10
refresh: true

- do:
search:
index: test
body:
_source: false
fields: [ metric ]
query:
match_all: {}

- match: { hits.total.value: 2 }
- length: { hits.hits: 2 }
- match: { hits.hits.0.fields.metric.0.min: 10 }
- match: { hits.hits.0.fields.metric.0.max: 100 }
- match: { hits.hits.0.fields.metric.0.sum: 200 }
- match: { hits.hits.0.fields.metric.0.value_count: 5 }
- match: { hits.hits.1.fields.metric.0.min: 50 }
- match: { hits.hits.1.fields.metric.0.max: 1000 }
- match: { hits.hits.1.fields.metric.0.sum: 5000 }
- match: { hits.hits.1.fields.metric.0.value_count: 10 }
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,58 @@ setup:
type: double
time_series_metric: gauge

- do:
indices.create:
index: test_aggregate_metric
body:
mappings:
properties:
metric:
type: aggregate_metric_double
metrics: [ min, max, value_count ]
default_metric: max

---
aggregate_metric on standard index:
- skip:
version: " - 8.4.99"
reason: aggregate_metric_double field caps changed in 8.5.0

- do:
field_caps:
index: test_aggregate_metric
fields: [ metric ]

- match: { fields.metric.aggregate_metric_double.searchable: true }
- match: { fields.metric.aggregate_metric_double.aggregatable: true }
- is_false: fields.metric.aggregate_metric_double.indices

---
aggregate_metric on standard index conflict with double:
- skip:
version: " - 8.4.99"
reason: aggregate_metric_double field caps changed in 8.5.0

- do:
indices.create:
index: test_double
body:
mappings:
properties:
metric:
type: double

- do:
field_caps:
index: [test_double, test_aggregate_metric]
fields: [ metric ]

- match: { fields.metric.aggregate_metric_double.searchable: true }
- match: { fields.metric.aggregate_metric_double.aggregatable: true }
- match: { fields.metric.aggregate_metric_double.indices: [ test_aggregate_metric ] }
- match: { fields.metric.double.searchable: true }
- match: { fields.metric.double.aggregatable: true }
- match: { fields.metric.double.indices: [ test_double ] }

---
# Test field_caps on a rollup index
Expand Down