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

Don't include _id, _type and _index keys in search response for inner hits #18995

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -439,13 +439,14 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.field("_shard", shard.shardId());
builder.field("_node", shard.nodeIdText());
}
if (shard != null) {
builder.field(Fields._INDEX, shard.indexText());
}
builder.field(Fields._TYPE, type);
builder.field(Fields._ID, id);
if (nestedIdentity != null) {
nestedIdentity.toXContent(builder, params);
} else {
if (shard != null) {
builder.field(Fields._INDEX, shard.indexText());
}
builder.field(Fields._TYPE, type);
builder.field(Fields._ID, id);
}
if (version != -1) {
builder.field(Fields._VERSION, version);
Expand Down
3 changes: 3 additions & 0 deletions docs/reference/migration/migrate_5_0/search.asciidoc
Expand Up @@ -180,6 +180,9 @@ with inner hits defined inside the query dsl.
* Source filtering for inner hits inside nested queries requires full field names instead of relative field names.
This is now consistent for source filtering on other places in the search API.

* Nested inner hits will now no longer include `_index`, `_type` and `_id` keys. For nested inner hits these values
are always the same as the `_index`, `_type` and `_id` keys of the root search hit.

==== Query Profiler

In the response for profiling queries, the `query_type` has been renamed to `type` and `lucene` has been renamed to
Expand Down
2 changes: 0 additions & 2 deletions docs/reference/search/request/inner-hits.asciidoc
Expand Up @@ -118,8 +118,6 @@ An example of a response snippet that could be generated from the above search r
"total": ...,
"hits": [
{
"_type": "question",
"_id": "1",
"_nested": {
"field": "comments",
"offset": 2
Expand Down
@@ -0,0 +1,84 @@
---
setup:
- do:
indices.create:
index: test
body:
mappings:
type_1: {
properties: {
nested_field : {
type: nested
}
}
}
type_2: {}
type_3: {
_parent: {
type: type_2
}
}

---
"Nested inner hits":
- do:
index:
index: test
type: type_1
id: 1
body: {
"nested_field" : [
{
"foo": "bar"
}
]
}

- do:
indices.refresh: {}

- do:
search:
body: { "query" : { "nested" : { "path" : "nested_field", "query" : { "match_all" : {} }, "inner_hits" : {} } } }
- match: { hits.total: 1 }
- match: { hits.hits.0._index: "test" }
- match: { hits.hits.0._type: "type_1" }
- match: { hits.hits.0._id: "1" }
- is_false: hits.hits.0.inner_hits.nested_field.hits.hits.0._index
- is_false: hits.hits.0.inner_hits.nested_field.hits.hits.0._type
- is_false: hits.hits.0.inner_hits.nested_field.hits.hits.0._id
- match: { hits.hits.0.inner_hits.nested_field.hits.hits.0._nested.field: "nested_field" }
- match: { hits.hits.0.inner_hits.nested_field.hits.hits.0._nested.offset: 0 }
- is_false: hits.hits.0.inner_hits.nested_field.hits.hits.0._nested.child

---
"Parent/child inner hits":
- do:
index:
index: test
type: type_2
id: 1
body: {"foo": "bar"}

- do:
index:
index: test
type: type_3
id: 1
parent: 1
body: {"bar": "baz"}

- do:
indices.refresh: {}

- do:
search:
body: { "query" : { "has_child" : { "type" : "type_3", "query" : { "match_all" : {} }, "inner_hits" : {} } } }
- match: { hits.total: 1 }
- match: { hits.hits.0._index: "test" }
- match: { hits.hits.0._type: "type_2" }
- match: { hits.hits.0._id: "1" }
- match: { hits.hits.0.inner_hits.type_3.hits.hits.0._index: "test" }
- match: { hits.hits.0.inner_hits.type_3.hits.hits.0._type: "type_3" }
- match: { hits.hits.0.inner_hits.type_3.hits.hits.0._id: "1" }
- is_false: hits.hits.0.inner_hits.type_3.hits.hits.0._nested