Skip to content

Commit

Permalink
ESQL: Load keyword fields missing doc_values (elastic#98639)
Browse files Browse the repository at this point in the history
This PR adds support for loading keyword fields 
having doc_values: false in their mapping.

The code follows the same code path as when loading text fields, l
oading field from the index (if stored is true) or extracting from
the _source.
  • Loading branch information
csoulios committed Aug 20, 2023
1 parent 001fcfb commit c331d92
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.elasticsearch.index.fielddata.SourceValueFetcherSortedBinaryIndexFieldData;
import org.elasticsearch.index.fielddata.StoredFieldSortedBinaryIndexFieldData;
import org.elasticsearch.index.mapper.IdFieldMapper;
import org.elasticsearch.index.mapper.KeywordFieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.SourceValueFetcher;
import org.elasticsearch.index.mapper.TextFieldMapper;
Expand All @@ -28,6 +29,8 @@

public final class ValueSources {

public static final String MATCH_ONLY_TEXT = "match_only_text";

private ValueSources() {}

public static List<ValueSourceInfo> sources(
Expand All @@ -46,18 +49,22 @@ public static List<ValueSourceInfo> sources(
continue; // the field does not exist in this context
}

// MatchOnlyTextFieldMapper class lives in the mapper-extras module. We use string equality
// for the field type name to avoid adding a dependency to the module
if (fieldType instanceof TextFieldMapper.TextFieldType || "match_only_text".equals(fieldType.typeName())) {
ValuesSource vs = textValueSource(ctx, fieldType);
sources.add(new ValueSourceInfo(CoreValuesSourceType.KEYWORD, vs, elementType, ctx.getIndexReader()));
continue;
}
if (fieldType.hasDocValues() == false) {
// MatchOnlyTextFieldMapper class lives in the mapper-extras module. We use string equality
// for the field type name to avoid adding a dependency to the module
if (fieldType instanceof KeywordFieldMapper.KeywordFieldType
|| fieldType instanceof TextFieldMapper.TextFieldType
|| MATCH_ONLY_TEXT.equals(fieldType.typeName())) {
ValuesSource vs = textValueSource(ctx, fieldType);
sources.add(new ValueSourceInfo(CoreValuesSourceType.KEYWORD, vs, elementType, ctx.getIndexReader()));
continue;
}

if (IdFieldMapper.NAME.equals(fieldType.name())) {
ValuesSource vs = new IdValueSource(new IdFieldIndexFieldData(CoreValuesSourceType.KEYWORD));
sources.add(new ValueSourceInfo(CoreValuesSourceType.KEYWORD, vs, elementType, ctx.getIndexReader()));
continue;
if (IdFieldMapper.NAME.equals(fieldType.name())) {
ValuesSource vs = new IdValueSource(new IdFieldIndexFieldData(CoreValuesSourceType.KEYWORD));
sources.add(new ValueSourceInfo(CoreValuesSourceType.KEYWORD, vs, elementType, ctx.getIndexReader()));
continue;
}
}

IndexFieldData<?> fieldData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,35 @@ multivalued keyword:
- length: {values: 1}
- match: {values.0.0: [diamonds, jack, of]}

---
keyword no doc_values:
- do:
indices.create:
index: test
body:
mappings:
properties:
card:
type: keyword
doc_values: false

- do:
bulk:
index: test
refresh: true
body:
- { "index": { } }
- { "card": ["jack", "of", "diamonds"] }

- do:
esql.query:
body:
query: 'from test'
- match: {columns.0.name: card}
- match: {columns.0.type: keyword}
- length: {values: 1}
- match: {values.0.0: [diamonds, jack, of]}

---
wildcard:
- do:
Expand Down

0 comments on commit c331d92

Please sign in to comment.