Skip to content

Commit d5ac3bb

Browse files
authored
Field capabilities - make keyword a family of field types (#58315) (#58483)
Introduces a new method on `MappedFieldType` to return a family type name which defaults to the field type. Changes `wildcard` and `constant_keyword` field types to return `keyword` for field capabilities. Relates to #53175
1 parent ec8d5ec commit d5ac3bb

File tree

9 files changed

+49
-24
lines changed

9 files changed

+49
-24
lines changed

docs/reference/search/field-caps.asciidoc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ query rewrites to `match_none` on every shard.
6767
==== {api-response-body-title}
6868

6969

70+
The types used in the response describe _families_ of field types.
71+
Normally a family type is the same as the field type declared in the mapping,
72+
but to simplify matters certain field types that behave identically are
73+
described using a family type. For example, `keyword`, `constant_keyword` and `wildcard`
74+
field types are all described as the `keyword` family type.
75+
76+
7077

7178
`searchable`::
7279
Whether this field is indexed for search on all indices.
@@ -75,8 +82,8 @@ query rewrites to `match_none` on every shard.
7582
Whether this field can be aggregated on all indices.
7683

7784
`indices`::
78-
The list of indices where this field has the same type, or null if all indices
79-
have the same type for the field.
85+
The list of indices where this field has the same family type, or null if all indices
86+
have the same family type for the field.
8087

8188
`non_searchable_indices`::
8289
The list of indices where this field is not searchable, or null if all indices

server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesIndexAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private FieldCapabilitiesIndexResponse shardOperation(final FieldCapabilitiesInd
124124
if (ft != null) {
125125
if (indicesService.isMetadataField(mapperService.getIndexSettings().getIndexVersionCreated(), field)
126126
|| fieldPredicate.test(ft.name())) {
127-
IndexFieldCapabilities fieldCap = new IndexFieldCapabilities(field, ft.typeName(),
127+
IndexFieldCapabilities fieldCap = new IndexFieldCapabilities(field, ft.familyTypeName(),
128128
ft.isSearchable(), ft.isAggregatable(), ft.meta());
129129
responseMap.put(field, fieldCap);
130130
} else {

server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ public int hashCode() {
135135

136136
/** Returns the name of this type, as would be specified in mapping properties */
137137
public abstract String typeName();
138+
139+
/** Returns the field family type, as used in field capabilities */
140+
public String familyTypeName() {
141+
return typeName();
142+
}
138143

139144
public String name() {
140145
return name;

x-pack/plugin/mapper-constant-keyword/src/main/java/org/elasticsearch/xpack/constantkeyword/mapper/ConstantKeywordFieldMapper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.elasticsearch.index.fielddata.plain.ConstantIndexFieldData;
3131
import org.elasticsearch.index.mapper.ConstantFieldType;
3232
import org.elasticsearch.index.mapper.FieldMapper;
33+
import org.elasticsearch.index.mapper.KeywordFieldMapper;
3334
import org.elasticsearch.index.mapper.MappedFieldType;
3435
import org.elasticsearch.index.mapper.Mapper;
3536
import org.elasticsearch.index.mapper.MapperParsingException;
@@ -151,6 +152,11 @@ public String value() {
151152
public String typeName() {
152153
return CONTENT_TYPE;
153154
}
155+
156+
@Override
157+
public String familyTypeName() {
158+
return KeywordFieldMapper.CONTENT_TYPE;
159+
}
154160

155161
@Override
156162
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {

x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/FieldExtractorTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void testConstantKeywordField() throws IOException {
128128
Map<String, Object> expected = new HashMap<>();
129129
expected.put(
130130
"columns",
131-
Arrays.asList(columnInfo("plain", "constant_keyword_field", "constant_keyword", JDBCType.VARCHAR, Integer.MAX_VALUE))
131+
Arrays.asList(columnInfo("plain", "constant_keyword_field", "keyword", JDBCType.VARCHAR, Integer.MAX_VALUE))
132132
);
133133
expected.put("rows", singletonList(singletonList(value)));
134134
assertResponse(expected, runSql("SELECT constant_keyword_field FROM test"));

x-pack/plugin/sql/qa/server/src/main/resources/alias.csv-spec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ emp_no |INTEGER |integer
4141
extra |STRUCT |object
4242
extra.info |STRUCT |object
4343
extra.info.gender |VARCHAR |keyword
44-
extra_gender |VARCHAR |constant_keyword
44+
extra_gender |VARCHAR |keyword
4545
extra_no |INTEGER |integer
4646
first_name |VARCHAR |text
4747
first_name.keyword |VARCHAR |keyword
@@ -50,7 +50,7 @@ hire_date |TIMESTAMP |datetime
5050
languages |TINYINT |byte
5151
last_name |VARCHAR |text
5252
last_name.keyword |VARCHAR |keyword
53-
null_constant |VARCHAR |constant_keyword
53+
null_constant |VARCHAR |keyword
5454
salary |INTEGER |integer
5555
;
5656

@@ -70,7 +70,7 @@ emp_no |INTEGER |integer
7070
extra |STRUCT |object
7171
extra.info |STRUCT |object
7272
extra.info.gender |VARCHAR |keyword
73-
extra_gender |VARCHAR |constant_keyword
73+
extra_gender |VARCHAR |keyword
7474
extra_no |INTEGER |integer
7575
first_name |VARCHAR |text
7676
first_name.keyword |VARCHAR |keyword
@@ -79,7 +79,7 @@ hire_date |TIMESTAMP |datetime
7979
languages |TINYINT |byte
8080
last_name |VARCHAR |text
8181
last_name.keyword |VARCHAR |keyword
82-
null_constant |VARCHAR |constant_keyword
82+
null_constant |VARCHAR |keyword
8383
salary |INTEGER |integer
8484
;
8585

x-pack/plugin/sql/qa/server/src/main/resources/command.csv-spec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ emp_no |INTEGER |integer
281281
extra |STRUCT |object
282282
extra.info |STRUCT |object
283283
extra.info.gender |VARCHAR |keyword
284-
extra_gender |VARCHAR |constant_keyword
284+
extra_gender |VARCHAR |keyword
285285
extra_no |INTEGER |integer
286286
first_name |VARCHAR |text
287287
first_name.keyword |VARCHAR |keyword
@@ -290,7 +290,7 @@ hire_date |TIMESTAMP |datetime
290290
languages |TINYINT |byte
291291
last_name |VARCHAR |text
292292
last_name.keyword |VARCHAR |keyword
293-
null_constant |VARCHAR |constant_keyword
293+
null_constant |VARCHAR |keyword
294294
salary |INTEGER |integer
295295
;
296296

@@ -310,7 +310,7 @@ emp_no |INTEGER |integer
310310
extra |STRUCT |object
311311
extra.info |STRUCT |object
312312
extra.info.gender |VARCHAR |keyword
313-
extra_gender |VARCHAR |constant_keyword
313+
extra_gender |VARCHAR |keyword
314314
extra_no |INTEGER |integer
315315
first_name |VARCHAR |text
316316
first_name.keyword |VARCHAR |keyword
@@ -319,7 +319,7 @@ hire_date |TIMESTAMP |datetime
319319
languages |TINYINT |byte
320320
last_name |VARCHAR |text
321321
last_name.keyword |VARCHAR |keyword
322-
null_constant |VARCHAR |constant_keyword
322+
null_constant |VARCHAR |keyword
323323
salary |INTEGER |integer
324324
;
325325

0 commit comments

Comments
 (0)