docs: add sort workaround

This commit is contained in:
Martijn van Groningen 2016-08-26 10:55:23 +02:00
parent 3ed0da5a58
commit 7c9af98a3c
2 changed files with 62 additions and 0 deletions

View File

@ -93,3 +93,34 @@ and will not match any documents for this query. This can be useful when
querying multiple indexes which might have different mappings. When set to
`false` (the default value) the query will throw an exception if the `type`
is not mapped.
[float]
==== Sorting
Parent documents can't be sorted by fields in matching child documents via the
regular sort options. If you need to sort parent document by field in the child
documents then you can should use the `function_score` query and then just sort
by `_score`.
Sorting blogs by child documents' `click_count` field:
[source,js]
--------------------------------------------------
GET /_search
{
"query": {
"has_child" : {
"type" : "blog_tag",
"score_mode" : "max",
"query" : {
"function_score" : {
"script_score": {
"script": "_score * doc['click_count'].value"
}
}
}
}
}
}
--------------------------------------------------
// CONSOLE

View File

@ -63,3 +63,34 @@ and will not match any documents for this query. This can be useful when
querying multiple indexes which might have different mappings. When set to
`false` (the default value) the query will throw an exception if the `type`
is not mapped.
[float]
==== Sorting
Child documents can't be sorted by fields in matching parent documents via the
regular sort options. If you need to sort child documents by field in the parent
documents then you can should use the `function_score` query and then just sort
by `_score`.
Sorting tags by parent document' `view_count` field:
[source,js]
--------------------------------------------------
GET /_search
{
"query": {
"has_parent" : {
"parent_type" : "blog",
"score" : true,
"query" : {
"function_score" : {
"script_score": {
"script": "_score * doc['view_count'].value"
}
}
}
}
}
}
--------------------------------------------------
// CONSOLE