Skip to content

Commit cd31448

Browse files
kolchfa-awsnatebower
authored andcommitted
Add has parent query (opensearch-project#8365)
* Add has parent query Signed-off-by: Fanit Kolchina <[email protected]> * Apply suggestions from code review Co-authored-by: Nathan Bower <[email protected]> Signed-off-by: kolchfa-aws <[email protected]> --------- Signed-off-by: Fanit Kolchina <[email protected]> Signed-off-by: kolchfa-aws <[email protected]> Co-authored-by: Nathan Bower <[email protected]>
1 parent 1285eb0 commit cd31448

File tree

6 files changed

+516
-3
lines changed

6 files changed

+516
-3
lines changed

_field-types/supported-field-types/join.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,8 @@ PUT testindex1
327327
- Multiple parents are not supported.
328328
- You can add a child document to an existing document only if the existing document is already marked as a parent.
329329
- You can add a new relation to an existing join field.
330+
331+
## Next steps
332+
333+
- Learn about [joining queries]({{site.url}}{{site.baseurl}}/query-dsl/joining/) on join fields.
334+
- Learn more about [retrieving inner hits]({{site.url}}{{site.baseurl}}/search-plugins/searching-data/inner-hits/).

_field-types/supported-field-types/nested.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,8 @@ Parameter | Description
314314
`include_in_parent` | A Boolean value that specifies whether all fields in the child nested object should also be added to the parent document in flattened form. Default is `false`.
315315
`include_in_root` | A Boolean value that specifies whether all fields in the child nested object should also be added to the root document in flattened form. Default is `false`.
316316
`properties` | Fields of this object, which can be of any supported type. New properties can be dynamically added to this object if `dynamic` is set to `true`.
317+
318+
## Next steps
319+
320+
- Learn about [joining queries]({{site.url}}{{site.baseurl}}/query-dsl/joining/) on nested fields.
321+
- Learn about [retrieving inner hits]({{site.url}}{{site.baseurl}}/search-plugins/searching-data/inner-hits/).

_query-dsl/joining/has-child.md

Lines changed: 140 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,140 @@ The response returns both brands:
176176
}
177177
```
178178

179+
## Retrieving inner hits
180+
181+
To return child documents that matched the query, provide the `inner_hits` parameter:
182+
183+
```json
184+
GET testindex1/_search
185+
{
186+
"query" : {
187+
"has_child": {
188+
"type":"product",
189+
"query": {
190+
"match" : {
191+
"name": "watch"
192+
}
193+
},
194+
"inner_hits": {}
195+
}
196+
}
197+
}
198+
```
199+
{% include copy-curl.html %}
200+
201+
The response contains child documents in the `inner_hits` field:
202+
203+
```json
204+
{
205+
"took": 52,
206+
"timed_out": false,
207+
"_shards": {
208+
"total": 1,
209+
"successful": 1,
210+
"skipped": 0,
211+
"failed": 0
212+
},
213+
"hits": {
214+
"total": {
215+
"value": 2,
216+
"relation": "eq"
217+
},
218+
"max_score": 1,
219+
"hits": [
220+
{
221+
"_index": "testindex1",
222+
"_id": "1",
223+
"_score": 1,
224+
"_source": {
225+
"name": "Luxury brand",
226+
"product_to_brand": "brand"
227+
},
228+
"inner_hits": {
229+
"product": {
230+
"hits": {
231+
"total": {
232+
"value": 1,
233+
"relation": "eq"
234+
},
235+
"max_score": 0.53899646,
236+
"hits": [
237+
{
238+
"_index": "testindex1",
239+
"_id": "3",
240+
"_score": 0.53899646,
241+
"_routing": "1",
242+
"_source": {
243+
"name": "Mechanical watch",
244+
"sales_count": 150,
245+
"product_to_brand": {
246+
"name": "product",
247+
"parent": "1"
248+
}
249+
}
250+
}
251+
]
252+
}
253+
}
254+
}
255+
},
256+
{
257+
"_index": "testindex1",
258+
"_id": "2",
259+
"_score": 1,
260+
"_source": {
261+
"name": "Economy brand",
262+
"product_to_brand": "brand"
263+
},
264+
"inner_hits": {
265+
"product": {
266+
"hits": {
267+
"total": {
268+
"value": 2,
269+
"relation": "eq"
270+
},
271+
"max_score": 0.53899646,
272+
"hits": [
273+
{
274+
"_index": "testindex1",
275+
"_id": "4",
276+
"_score": 0.53899646,
277+
"_routing": "2",
278+
"_source": {
279+
"name": "Electronic watch",
280+
"sales_count": 300,
281+
"product_to_brand": {
282+
"name": "product",
283+
"parent": "2"
284+
}
285+
}
286+
},
287+
{
288+
"_index": "testindex1",
289+
"_id": "5",
290+
"_score": 0.53899646,
291+
"_routing": "2",
292+
"_source": {
293+
"name": "Digital watch",
294+
"sales_count": 100,
295+
"product_to_brand": {
296+
"name": "product",
297+
"parent": "2"
298+
}
299+
}
300+
}
301+
]
302+
}
303+
}
304+
}
305+
}
306+
]
307+
}
308+
}
309+
```
310+
311+
For more information about retrieving inner hits, see [Inner hits]({{site.url}}{{site.baseurl}}/search-plugins/searching-data/inner-hits/).
312+
179313
## Parameters
180314

181315
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
188322
| `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. |
189323
| `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`.|
190324
| `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`. |
325+
| `inner_hits` | Optional | If provided, returns the underlying hits (child documents) that matched the query. |
191326

192327

193328
## Sorting limitations
@@ -256,4 +391,8 @@ The response contains the brands sorted by the highest child `sales_count`:
256391
]
257392
}
258393
}
259-
```
394+
```
395+
396+
## Next steps
397+
398+
- Learn more about [retrieving inner hits]({{site.url}}{{site.baseurl}}/search-plugins/searching-data/inner-hits/).

0 commit comments

Comments
 (0)