diff --git a/docs/changelog/110825.yaml b/docs/changelog/110825.yaml new file mode 100644 index 0000000000000..e4fb56a9a5e7d --- /dev/null +++ b/docs/changelog/110825.yaml @@ -0,0 +1,6 @@ +pr: 110825 +summary: Do not include root level `_type` field if it is not a metadata field +area: Mapping +type: bug +issues: + - 110438 diff --git a/modules/parent-join/src/yamlRestTest/resources/rest-api-spec/test/20_parent_join.yml b/modules/parent-join/src/yamlRestTest/resources/rest-api-spec/test/20_parent_join.yml index daa9068162ffa..99fdc658e42f2 100644 --- a/modules/parent-join/src/yamlRestTest/resources/rest-api-spec/test/20_parent_join.yml +++ b/modules/parent-join/src/yamlRestTest/resources/rest-api-spec/test/20_parent_join.yml @@ -161,3 +161,56 @@ teardown: mappings: properties: join_field: { "type": "join", "relations": { "parent": "child", "child": "grand_child" }, "fields": {"keyword": {"type": "keyword"}} } + + +--- +"join on field named _type": + - requires: + cluster_features: [ "gte_v8.14.0" ] + reason: "deprecation added in 8.14" + + - do: + indices.create: + index: type-join + body: + mappings: + properties: + text: { "type": "keyword" } + _type: { "type": "join", "relations": { "question": "answer" }} + + - do: + bulk: + index: type-join + refresh: true + body: + - '{ "index": {"_id": "1"}}' + - '{ "text": "What species does chewbacca belong to?", "_type": { "name": "question" }}' + - '{ "index": {"_id": "2"}}' + - '{ "text": "How did Yoda die?", "_type": { "name": "question" }}' + + - do: + bulk: + index: type-join + refresh: true + body: + - '{ "index": {"_id": "3"}}' + - '{ "text": "Wookie", "_type": { "name": "answer", "parent": "1" }}' + - '{ "index": {"_id": "4"}}' + - '{ "text": "Old age", "_type": { "name": "answer", "parent": "2" }}' + + - do: + search: + index: type-join + body: { query: { match_all: { } } } + + - length: { hits.hits: 2 } + + - match: { hits.hits.0._id: "1" } + - match: { hits.hits.0._type: null } + - match: { hits.hits.0._source._type.name: "question" } + - match: { hits.hits.0._source.text: "What species does chewbacca belong to?"} + + - match: { hits.hits.1._id: "2" } + - match: { hits.hits.1._type: null } + - match: { hits.hits.1._source._type.name: "question" } + - match: { hits.hits.1._source.text: "How did Yoda die?" } diff --git a/server/src/main/java/org/elasticsearch/search/fetch/subphase/FieldFetcher.java b/server/src/main/java/org/elasticsearch/search/fetch/subphase/FieldFetcher.java index fab794615a10d..9c198b6f44b92 100644 --- a/server/src/main/java/org/elasticsearch/search/fetch/subphase/FieldFetcher.java +++ b/server/src/main/java/org/elasticsearch/search/fetch/subphase/FieldFetcher.java @@ -11,6 +11,7 @@ import org.apache.lucene.index.LeafReaderContext; import org.elasticsearch.common.document.DocumentField; import org.elasticsearch.common.regex.Regex; +import org.elasticsearch.index.mapper.LegacyTypeFieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.NestedValueFetcher; import org.elasticsearch.index.mapper.ValueFetcher; @@ -58,6 +59,11 @@ public static FieldFetcher create(SearchExecutionContext context, Collection