I am having trouble getting a random set of documents when performing a nested query with inner_hits. I need the documents to be random, not the inner hits themselves.
Here's the mapping for the examples:
{
"mappings": {
"doc": {
"properties": {
"faces": {
"type": "nested",
"properties": {
"cluster_id": {
"type": "integer"
}
}
}
}
}
}
}
Now, just as a sanity check, the following query returns a random set of documents:
{
"query": {
"function_score": {
"random_score": {},
"query": {
"match_all": {}
}
}
}
}
But now if I try to modify that to return the inner hits for a specific cluster id, then the results are not random anymore. Here's the query:
{
"query": {
"function_score": {
"random_score": {},
"query": {
"nested": {
"path": "faces",
"query": {
"bool": {
"filter": [
{
"term": {
"faces.cluster_id": 0
}
}
]
}
},
"inner_hits": {}
}
}
}
}
}
I have also tried wrapping the query bit of the nested query in the function_score, but the results are the same, no random ordering.
Any help is greatly appreciated!