Skip to content

Commit

Permalink
Mapped field types searchable with doc values (elastic#97724)
Browse files Browse the repository at this point in the history
* Mapped field types searchable with doc values

When using TSDB, time series metrics aren't indexed but do have doc values.
Field caps should report those fields as searchable.
  • Loading branch information
tmgordeeva authored Aug 16, 2023
1 parent b337f9b commit 171bcbb
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/97724.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 97724
summary: Mapped field types searchable with doc values
area: TSDB
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ public boolean mayExistInIndex(SearchExecutionContext context) {
return context.fieldExistsInIndex(name());
}

@Override
public boolean isSearchable() {
return isIndexed() || hasDocValues();
}

@Override
public Query termQuery(Object value, SearchExecutionContext context) {
failIfNotIndexedNorDocValuesFallback(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,25 @@ public void testNoDocValues() throws Exception {
assertEquals(1230, pointField.numericValue().longValue());
}

public void testDocValuesSearchable() throws Exception {
boolean[] indexables = new boolean[] { true, false };
boolean[] hasDocValues = new boolean[] { true, false };
for (boolean indexable : indexables) {
for (boolean hasDocValue : hasDocValues) {
MapperService mapperService = createMapperService(
fieldMapping(
b -> b.field("type", "scaled_float")
.field("index", indexable)
.field("doc_values", hasDocValue)
.field("scaling_factor", 10.0)
)
);
MappedFieldType fieldType = mapperService.fieldType("field");
assertEquals(fieldType.isSearchable(), indexable || hasDocValue);
}
}
}

public void testStore() throws Exception {
DocumentMapper mapper = createDocumentMapper(
fieldMapping(b -> b.field("type", "scaled_float").field("store", true).field("scaling_factor", 10.0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,43 @@ aggregate_double_metric with wrong time series mappings:
metrics: [min, max, sum, value_count]
default_metric: max
time_series_metric: histogram

---
"Field caps with tsdb":
- skip:
version: " - 8.7.99"
reason: "Field caps fix in 8.9"

- do:
indices.create:
index: tsdb-fieldcap
body:
settings:
number_of_replicas: 0
mode: time_series
routing_path: [field1]
time_series:
start_time: "2000-01-01T00:00:00Z"
end_time: "2099-12-31T23:59:59Z"
mappings:
properties:
field1:
type: keyword
time_series_dimension: true
field2:
type: long
time_series_metric: gauge
field3:
type: scaled_float
scaling_factor: 100
time_series_metric: gauge

- do:
field_caps:
index: tsdb-fieldcap
fields: "field*"

- match: {indices: ["tsdb-fieldcap"]}
- match: {fields.field1.keyword.type: keyword}
- match: {fields.field3.scaled_float.type: scaled_float}
- match: {fields.field3.scaled_float.searchable: true}

0 comments on commit 171bcbb

Please sign in to comment.