Pagination within a terms aggregation

I have a nested field datas which is inside the also nested field documents.

I'd like to retrieve the paginated list of concepts buckets (built using a terms aggregation).

I managed to retrieve the list without any problem, but I can't manage to paginate this list using size and from within a bucket_sort :

{
  'aggs': {
    'all_datas': {
      'aggs': {
        'concepts': {
          'aggs': {
            'pagination': {
              'bucket_sort': {
                'from': <offset>,
                'size': <limit>
              }
            }
          },
          'terms': {
            'field': 'documents.datas.thesaurus.concept_code.keyword',
            'show_term_doc_count_error': true
          }
        }
      },
      'nested': {
        'path': 'documents.datas'
      }
    }
  }
}

Any idea why it is not working ?

It seems that terms aggregation does not support bucket_sort. I solved my problem using partitions:

I first fetched the total number of concept using cardinality, and I then used the following json:

{
  'aggs': {
    'all_datas': {
      'aggs': {
        'concepts': {
          'terms': {
            'field': 'documents.datas.thesaurus.concept_code.keyword',
            'show_term_doc_count_error': true,
            'size': <limit>,
            'include': {
               "partition": <floor(offset / limit)>,
               "num_partitions": <ceil(cardinality/limit)>
            }
          }
        }
      },
      'nested': {
        'path': 'documents.datas'
      }
    }
  }
}

The only real constraint is that offset must be a multiple of limit to not obtain duplicate result between "pages".

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.