generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 617
Add has parent query #8365
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
Merged
Merged
Add has parent query #8365
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,6 +176,140 @@ The response returns both brands: | |
} | ||
``` | ||
|
||
## Retrieving inner hits | ||
|
||
To return child documents that matched the query, provide the `inner_hits` parameter: | ||
|
||
```json | ||
GET testindex1/_search | ||
{ | ||
"query" : { | ||
"has_child": { | ||
"type":"product", | ||
"query": { | ||
"match" : { | ||
"name": "watch" | ||
} | ||
}, | ||
"inner_hits": {} | ||
} | ||
} | ||
} | ||
``` | ||
{% include copy-curl.html %} | ||
|
||
The response contains child documents in the `inner_hits` field: | ||
|
||
```json | ||
{ | ||
"took": 52, | ||
"timed_out": false, | ||
"_shards": { | ||
"total": 1, | ||
"successful": 1, | ||
"skipped": 0, | ||
"failed": 0 | ||
}, | ||
"hits": { | ||
"total": { | ||
"value": 2, | ||
"relation": "eq" | ||
}, | ||
"max_score": 1, | ||
"hits": [ | ||
{ | ||
"_index": "testindex1", | ||
"_id": "1", | ||
"_score": 1, | ||
"_source": { | ||
"name": "Luxury brand", | ||
"product_to_brand": "brand" | ||
}, | ||
"inner_hits": { | ||
"product": { | ||
"hits": { | ||
"total": { | ||
"value": 1, | ||
"relation": "eq" | ||
}, | ||
"max_score": 0.53899646, | ||
"hits": [ | ||
{ | ||
"_index": "testindex1", | ||
"_id": "3", | ||
"_score": 0.53899646, | ||
"_routing": "1", | ||
"_source": { | ||
"name": "Mechanical watch", | ||
"sales_count": 150, | ||
"product_to_brand": { | ||
"name": "product", | ||
"parent": "1" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
"_index": "testindex1", | ||
"_id": "2", | ||
"_score": 1, | ||
"_source": { | ||
"name": "Economy brand", | ||
"product_to_brand": "brand" | ||
}, | ||
"inner_hits": { | ||
"product": { | ||
"hits": { | ||
"total": { | ||
"value": 2, | ||
"relation": "eq" | ||
}, | ||
"max_score": 0.53899646, | ||
"hits": [ | ||
{ | ||
"_index": "testindex1", | ||
"_id": "4", | ||
"_score": 0.53899646, | ||
"_routing": "2", | ||
"_source": { | ||
"name": "Electronic watch", | ||
"sales_count": 300, | ||
"product_to_brand": { | ||
"name": "product", | ||
"parent": "2" | ||
} | ||
} | ||
}, | ||
{ | ||
"_index": "testindex1", | ||
"_id": "5", | ||
"_score": 0.53899646, | ||
"_routing": "2", | ||
"_source": { | ||
"name": "Digital watch", | ||
"sales_count": 100, | ||
"product_to_brand": { | ||
"name": "product", | ||
"parent": "2" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
|
||
For more information about retrieving inner hits, see [Inner hits]({{site.url}}{{site.baseurl}}/search-plugins/searching-data/inner-hits/). | ||
|
||
## Parameters | ||
|
||
The following table lists all top-level parameters supported by `has_child` queries. | ||
|
@@ -188,6 +322,7 @@ The following table lists all top-level parameters supported by `has_child` quer | |
| `max_children` | Optional | The maximum number of matching child documents for a parent document. If exceeded, the parent document is excluded from the search results. | | ||
| `min_children` | Optional | The minimum number of matching child documents required for a parent document to be included in the results. If not met, the parent is excluded. Default is `1`.| | ||
| `score_mode` | Optional | Defines how scores of matching child documents influence the parent document's score. Valid values are: <br> - `none`: Ignores the relevance scores of child documents and assigns a score of `0` to the parent document. <br> - `avg`: Uses the average relevance score of all matching child documents. <br> - `max`: Assigns the highest relevance score from the matching child documents to the parent. <br> - `min`: Assigns the lowest relevance score from the matching child documents to the parent. <br> - `sum`: Sums the relevance scores of all matching child documents. <br> Default is `none`. | | ||
| `inner_hits` | Optional | If provided, returns the underlying hits (child documents) that matched the query. | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is "underlying" necessary here? "matched" => "match"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes (see above) |
||
|
||
|
||
## Sorting limitations | ||
|
@@ -256,4 +391,8 @@ The response contains the brands sorted by the highest child `sales_count`: | |
] | ||
} | ||
} | ||
``` | ||
``` | ||
|
||
## Next steps | ||
|
||
- Learn more about [retrieving inner hits]({{site.url}}{{site.baseurl}}/search-plugins/searching-data/inner-hits/). |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"matched" => "match"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to leave as "matched" because the parent documents are returned as a consequence of the child documents matching the query.