From 6a2eeedf37d1d217c50f18c55c5654fe8f68f140 Mon Sep 17 00:00:00 2001 From: Salvatore Campagna Date: Fri, 12 Jul 2024 14:57:46 +0200 Subject: [PATCH 1/3] fix: do not include root level _type if not a metadata field --- .../rest-api-spec/test/20_parent_join.yml | 53 +++++++++++++++++++ .../search/fetch/subphase/FieldFetcher.java | 6 +++ 2 files changed, 59 insertions(+) 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..fd17d7df90870 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 Date: Fri, 12 Jul 2024 15:05:41 +0200 Subject: [PATCH 2/3] nit: missing question mark --- .../resources/rest-api-spec/test/20_parent_join.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 fd17d7df90870..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 @@ -184,7 +184,7 @@ teardown: refresh: true body: - '{ "index": {"_id": "1"}}' - - '{ "text": "What species does chewbacca belong to", "_type": { "name": "question" }}' + - '{ "text": "What species does chewbacca belong to?", "_type": { "name": "question" }}' - '{ "index": {"_id": "2"}}' - '{ "text": "How did Yoda die?", "_type": { "name": "question" }}' @@ -208,7 +208,7 @@ teardown: - 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.0._source.text: "What species does chewbacca belong to?"} - match: { hits.hits.1._id: "2" } - match: { hits.hits.1._type: null } From 7a1fba267a52ccff6b0d59140327ff6d0fa0d3e7 Mon Sep 17 00:00:00 2001 From: Salvatore Campagna <93581129+salvatore-campagna@users.noreply.github.com> Date: Fri, 12 Jul 2024 19:33:47 +0200 Subject: [PATCH 3/3] Update docs/changelog/110825.yaml --- docs/changelog/110825.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 docs/changelog/110825.yaml 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