1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
[[query-dsl-has-parent-filter]]
=== Has Parent Filter
The `has_parent` filter accepts a query and a parent type. The query is
executed in the parent document space, which is specified by the parent
type. This filter returns child documents which associated parents have
matched. For the rest `has_parent` filter has the same options and works
in the same manner as the `has_child` filter.
[float]
==== Filter example
[source,js]
--------------------------------------------------
{
"has_parent" : {
"parent_type" : "blog",
"query" : {
"term" : {
"tag" : "something"
}
}
}
}
--------------------------------------------------
The `parent_type` field name can also be abbreviated to `type`.
The way that the filter is implemented is by first running the parent
query, doing the matching up to the child doc for each document matched.
The `has_parent` filter also accepts a filter instead of a query:
[source,js]
--------------------------------------------------
{
"has_parent" : {
"type" : "blog",
"filter" : {
"term" : {
"text" : "bonsai three"
}
}
}
}
--------------------------------------------------
[float]
==== Memory Considerations
In order to support parent-child joins, all of the (string) parent IDs
must be resident in memory (in the <<index-modules-fielddata,field data cache>>.
Additionally, every child document is mapped to its parent using a long
value (approximately). It is advisable to keep the string parent ID short
in order to reduce memory usage.
You can check how much memory is being used by the ID cache using the
<<indices-stats,indices stats>> or <<cluster-nodes-stats,nodes stats>>
APIS, eg:
[source,js]
--------------------------------------------------
curl -XGET "http://localhost:9200/_stats/id_cache?pretty&human"
--------------------------------------------------
[float]
==== Caching
The `has_parent` filter cannot be cached in the filter cache. The `_cache`
and `_cache_key` options are a no-op in this filter. Also any filter that
wraps the `has_parent` filter either directly or indirectly will not be cached.
|