You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _field-types/supported-field-types/nested.md
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -314,3 +314,8 @@ Parameter | Description
314
314
`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`.
315
315
`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`.
316
316
`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/).
Copy file name to clipboardExpand all lines: _query-dsl/joining/has-child.md
+140-1Lines changed: 140 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -176,6 +176,140 @@ The response returns both brands:
176
176
}
177
177
```
178
178
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
+
179
313
## Parameters
180
314
181
315
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
188
322
|`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. |
189
323
|`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`.|
190
324
|`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. |
191
326
192
327
193
328
## Sorting limitations
@@ -256,4 +391,8 @@ The response contains the brands sorted by the highest child `sales_count`:
256
391
]
257
392
}
258
393
}
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