Paul Preibisch
Paul Preibisch

Reputation: 4332

how can i paginate a nested query in elasticsearch

My elastic search mapping of "tags" has nested Videos array of objects

When i do a match_all query, all the tags are returned, and each tag has many videos attached.

I want to limit it to only X videos returned. How can I paginate the nested objects?

Upvotes: 1

Views: 1335

Answers (1)

AlainIb
AlainIb

Reputation: 4728

take a look at inner hits with size option : https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-inner-hits.html

try something like this

{
    "_source": false,
    "fields":["your_fields"],
   "size": 10,
   "query": {
      "match_all": {}
   },
   "inner_hits" : {
        "comments" : {
            "path" : { 
                "comments" : { 
                    "size":5,
                    "query" : {
                        "match_all": {}
                    }
                }
            }
        }
    }
}

Upvotes: 2

Related Questions