inner_hits: Don't include `_id`, `_type` and `_index` keys in search response for inner hits
Closes #18091
This commit is contained in:
parent
3748abfd7a
commit
5ad2fdaa8e
|
@ -439,13 +439,14 @@ public class InternalSearchHit implements SearchHit {
|
||||||
builder.field("_shard", shard.shardId());
|
builder.field("_shard", shard.shardId());
|
||||||
builder.field("_node", shard.nodeIdText());
|
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) {
|
if (nestedIdentity != null) {
|
||||||
nestedIdentity.toXContent(builder, params);
|
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) {
|
if (version != -1) {
|
||||||
builder.field(Fields._VERSION, version);
|
builder.field(Fields._VERSION, version);
|
||||||
|
|
|
@ -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.
|
* 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.
|
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
|
==== Query Profiler
|
||||||
|
|
||||||
In the response for profiling queries, the `query_type` has been renamed to `type` and `lucene` has been renamed to
|
In the response for profiling queries, the `query_type` has been renamed to `type` and `lucene` has been renamed to
|
||||||
|
|
|
@ -118,8 +118,6 @@ An example of a response snippet that could be generated from the above search r
|
||||||
"total": ...,
|
"total": ...,
|
||||||
"hits": [
|
"hits": [
|
||||||
{
|
{
|
||||||
"_type": "question",
|
|
||||||
"_id": "1",
|
|
||||||
"_nested": {
|
"_nested": {
|
||||||
"field": "comments",
|
"field": "comments",
|
||||||
"offset": 2
|
"offset": 2
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue