Skip to content

Commit 47df3b4

Browse files
committed
keyword fields
1 parent 3703533 commit 47df3b4

File tree

5 files changed

+13
-17
lines changed

5 files changed

+13
-17
lines changed

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/type/KeywordEsField.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.elasticsearch.common.io.stream.StreamOutput;
1111

1212
import java.io.IOException;
13-
import java.util.Collections;
1413
import java.util.Map;
1514
import java.util.Objects;
1615

@@ -26,23 +25,16 @@ public class KeywordEsField extends EsField {
2625
private final int precision;
2726
private final boolean normalized;
2827

29-
public KeywordEsField(String name) {
30-
this(name, Collections.emptyMap(), true, Short.MAX_VALUE, false);
31-
}
32-
33-
public KeywordEsField(String name, Map<String, EsField> properties, boolean hasDocValues, int precision, boolean normalized) {
34-
this(name, properties, hasDocValues, precision, normalized, false);
35-
}
36-
3728
public KeywordEsField(
3829
String name,
3930
Map<String, EsField> properties,
4031
boolean hasDocValues,
4132
int precision,
4233
boolean normalized,
43-
boolean isAlias
34+
boolean isAlias,
35+
TimeSeriesFieldType timeSeriesFieldType
4436
) {
45-
this(name, KEYWORD, properties, hasDocValues, precision, normalized, isAlias, TimeSeriesFieldType.UNKNOWN);
37+
this(name, KEYWORD, properties, hasDocValues, precision, normalized, isAlias, timeSeriesFieldType);
4638
}
4739

4840
protected KeywordEsField(

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/type/PotentiallyUnmappedKeywordEsField.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.elasticsearch.common.io.stream.StreamInput;
1010

1111
import java.io.IOException;
12+
import java.util.Collections;
1213

1314
/**
1415
* This class is used as a marker for fields that may be unmapped, where an unmapped field is a field which exists in the _source but is not
@@ -17,7 +18,7 @@
1718
*/
1819
public class PotentiallyUnmappedKeywordEsField extends KeywordEsField {
1920
public PotentiallyUnmappedKeywordEsField(String name) {
20-
super(name);
21+
super(name, Collections.emptyMap(), true, Short.MAX_VALUE, false, false, TimeSeriesFieldType.UNKNOWN);
2122
}
2223

2324
public PotentiallyUnmappedKeywordEsField(StreamInput in) throws IOException {

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/LoadMapping.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private static void walkMapping(String name, Object value, Map<String, EsField>
106106
} else if (esDataType == KEYWORD) {
107107
int length = intSetting(content.get("ignore_above"), Short.MAX_VALUE);
108108
boolean normalized = Strings.hasText(textSetting(content.get("normalizer"), null));
109-
field = new KeywordEsField(name, properties, docValues, length, normalized);
109+
field = new KeywordEsField(name, properties, docValues, length, normalized, false, EsField.TimeSeriesFieldType.NONE);
110110
} else if (esDataType == DATETIME) {
111111
field = DateEsField.dateEsField(name, properties, docValues);
112112
} else if (esDataType == UNSUPPORTED) {

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/IndexResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ private static EsField createField(
225225
int length = Short.MAX_VALUE;
226226
// TODO: to check whether isSearchable/isAggregateable takes into account the presence of the normalizer
227227
boolean normalized = false;
228-
return new KeywordEsField(name, new HashMap<>(), aggregatable, length, normalized, isAlias);
228+
return new KeywordEsField(name, new HashMap<>(), aggregatable, length, normalized, isAlias, timeSeriesFieldType);
229229
}
230230
if (type == DATETIME) {
231231
return DateEsField.dateEsField(name, new HashMap<>(), aggregatable);

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/type/KeywordEsFieldTests.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ static KeywordEsField randomKeywordEsField(int maxPropertiesDepth) {
2121
int precision = randomInt();
2222
boolean normalized = randomBoolean();
2323
boolean isAlias = randomBoolean();
24-
return new KeywordEsField(name, properties, hasDocValues, precision, normalized, isAlias);
24+
EsField.TimeSeriesFieldType tsType = randomFrom(EsField.TimeSeriesFieldType.values());
25+
return new KeywordEsField(name, properties, hasDocValues, precision, normalized, isAlias, tsType);
2526
}
2627

2728
@Override
@@ -37,15 +38,17 @@ protected KeywordEsField mutate(KeywordEsField instance) {
3738
int precision = instance.getPrecision();
3839
boolean normalized = instance.getNormalized();
3940
boolean isAlias = instance.isAlias();
40-
switch (between(0, 5)) {
41+
EsField.TimeSeriesFieldType tsType = instance.getTimeSeriesFieldType();
42+
switch (between(0, 6)) {
4143
case 0 -> name = randomAlphaOfLength(name.length() + 1);
4244
case 1 -> properties = randomValueOtherThan(properties, () -> randomProperties(4));
4345
case 2 -> hasDocValues = false == hasDocValues;
4446
case 3 -> precision = randomValueOtherThan(precision, ESTestCase::randomInt);
4547
case 4 -> normalized = false == normalized;
4648
case 5 -> isAlias = false == isAlias;
49+
case 6 -> tsType = randomValueOtherThan(tsType, () -> randomFrom(EsField.TimeSeriesFieldType.values()));
4750
default -> throw new IllegalArgumentException();
4851
}
49-
return new KeywordEsField(name, properties, hasDocValues, precision, normalized, isAlias);
52+
return new KeywordEsField(name, properties, hasDocValues, precision, normalized, isAlias, tsType);
5053
}
5154
}

0 commit comments

Comments
 (0)