Skip to content

Commit e48eaf5

Browse files
committed
docs: added p/c sort example
1 parent 7181ef5 commit e48eaf5

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

docs/reference/query-dsl/has-parent-query.asciidoc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,32 @@ matching parent document. The score mode can be specified with the
4747
}
4848
}
4949
--------------------------------------------------
50+
51+
[float]
52+
==== Sorting
53+
54+
Child documents can't be sorted by fields in matching parent documents via the
55+
regular sort options. If you need to sort child documents by field in the parent
56+
documents then you can should use the `function_score` query and then just sort
57+
by `_score`.
58+
59+
Sorting tags by parent document' `view_count` field:
60+
61+
[source,js]
62+
--------------------------------------------------
63+
{
64+
"query": {
65+
"has_parent" : {
66+
"parent_type" : "blog",
67+
"score_mode" : "score",
68+
"query" : {
69+
"function_score" : {
70+
"script_score": {
71+
"script": "_score * doc['view_count'].value"
72+
}
73+
}
74+
}
75+
}
76+
}
77+
}
78+
--------------------------------------------------

0 commit comments

Comments
 (0)