Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field capabilities - make keyword a family of field types (#58315) #58483

Merged
merged 1 commit into from
Jun 24, 2020
Merged
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
11 changes: 9 additions & 2 deletions docs/reference/search/field-caps.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ query rewrites to `match_none` on every shard.
==== {api-response-body-title}


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



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

`indices`::
The list of indices where this field has the same type, or null if all indices
have the same type for the field.
The list of indices where this field has the same family type, or null if all indices
have the same family type for the field.

`non_searchable_indices`::
The list of indices where this field is not searchable, or null if all indices
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private FieldCapabilitiesIndexResponse shardOperation(final FieldCapabilitiesInd
if (ft != null) {
if (indicesService.isMetadataField(mapperService.getIndexSettings().getIndexVersionCreated(), field)
|| fieldPredicate.test(ft.name())) {
IndexFieldCapabilities fieldCap = new IndexFieldCapabilities(field, ft.typeName(),
IndexFieldCapabilities fieldCap = new IndexFieldCapabilities(field, ft.familyTypeName(),
ft.isSearchable(), ft.isAggregatable(), ft.meta());
responseMap.put(field, fieldCap);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ public int hashCode() {

/** Returns the name of this type, as would be specified in mapping properties */
public abstract String typeName();

/** Returns the field family type, as used in field capabilities */
public String familyTypeName() {
return typeName();
}

public String name() {
return name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.elasticsearch.index.fielddata.plain.ConstantIndexFieldData;
import org.elasticsearch.index.mapper.ConstantFieldType;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.KeywordFieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperParsingException;
Expand Down Expand Up @@ -151,6 +152,11 @@ public String value() {
public String typeName() {
return CONTENT_TYPE;
}

@Override
public String familyTypeName() {
return KeywordFieldMapper.CONTENT_TYPE;
}

@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void testConstantKeywordField() throws IOException {
Map<String, Object> expected = new HashMap<>();
expected.put(
"columns",
Arrays.asList(columnInfo("plain", "constant_keyword_field", "constant_keyword", JDBCType.VARCHAR, Integer.MAX_VALUE))
Arrays.asList(columnInfo("plain", "constant_keyword_field", "keyword", JDBCType.VARCHAR, Integer.MAX_VALUE))
);
expected.put("rows", singletonList(singletonList(value)));
assertResponse(expected, runSql("SELECT constant_keyword_field FROM test"));
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugin/sql/qa/server/src/main/resources/alias.csv-spec
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ emp_no |INTEGER |integer
extra |STRUCT |object
extra.info |STRUCT |object
extra.info.gender |VARCHAR |keyword
extra_gender |VARCHAR |constant_keyword
extra_gender |VARCHAR |keyword
extra_no |INTEGER |integer
first_name |VARCHAR |text
first_name.keyword |VARCHAR |keyword
Expand All @@ -50,7 +50,7 @@ hire_date |TIMESTAMP |datetime
languages |TINYINT |byte
last_name |VARCHAR |text
last_name.keyword |VARCHAR |keyword
null_constant |VARCHAR |constant_keyword
null_constant |VARCHAR |keyword
salary |INTEGER |integer
;

Expand All @@ -70,7 +70,7 @@ emp_no |INTEGER |integer
extra |STRUCT |object
extra.info |STRUCT |object
extra.info.gender |VARCHAR |keyword
extra_gender |VARCHAR |constant_keyword
extra_gender |VARCHAR |keyword
extra_no |INTEGER |integer
first_name |VARCHAR |text
first_name.keyword |VARCHAR |keyword
Expand All @@ -79,7 +79,7 @@ hire_date |TIMESTAMP |datetime
languages |TINYINT |byte
last_name |VARCHAR |text
last_name.keyword |VARCHAR |keyword
null_constant |VARCHAR |constant_keyword
null_constant |VARCHAR |keyword
salary |INTEGER |integer
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ emp_no |INTEGER |integer
extra |STRUCT |object
extra.info |STRUCT |object
extra.info.gender |VARCHAR |keyword
extra_gender |VARCHAR |constant_keyword
extra_gender |VARCHAR |keyword
extra_no |INTEGER |integer
first_name |VARCHAR |text
first_name.keyword |VARCHAR |keyword
Expand All @@ -290,7 +290,7 @@ hire_date |TIMESTAMP |datetime
languages |TINYINT |byte
last_name |VARCHAR |text
last_name.keyword |VARCHAR |keyword
null_constant |VARCHAR |constant_keyword
null_constant |VARCHAR |keyword
salary |INTEGER |integer
;

Expand All @@ -310,7 +310,7 @@ emp_no |INTEGER |integer
extra |STRUCT |object
extra.info |STRUCT |object
extra.info.gender |VARCHAR |keyword
extra_gender |VARCHAR |constant_keyword
extra_gender |VARCHAR |keyword
extra_no |INTEGER |integer
first_name |VARCHAR |text
first_name.keyword |VARCHAR |keyword
Expand All @@ -319,7 +319,7 @@ hire_date |TIMESTAMP |datetime
languages |TINYINT |byte
last_name |VARCHAR |text
last_name.keyword |VARCHAR |keyword
null_constant |VARCHAR |constant_keyword
null_constant |VARCHAR |keyword
salary |INTEGER |integer
;

Expand Down
Loading