2

First of all, I want to say that the requirement I want to achieve is working very well on SOLR 5.3.1 but not on ElasticSearch 6.2 as a service on AWS.

My actual query is very large and complex and it is working fine on kibana but not when I cross the from = 100 and size = 50 as it is showing error on kibana console,

What I know:

For normal search, the maximum from can be 10000 and for aggregated search, the maximum from can be 100

If I cross that limit then I've to change the maximum limit which is not possible as I am using ES on AWS as a service OR I've use scroll API with scroll id feature to get paginated data.

The Scroll API works fine as I've used it to another part of my project but when I try the same Scroll with aggregation it is not working as expected.

Here with Scroll API, the first search gets the aggregated data but the second calling with scroll id not returns the Aggregated results only showing the Hits result

Query on Kibana

GET /properties/_search
{
  "size": 10,
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "published": true
          }
        },
        {
          "match": {
            "country": "South Africa"
          }
        }
      ]
    }
  },
  "aggs": {
    "aggs_by_feed": {
      "terms": {
        "field": "feed",
        "order": {
          "_key": "desc"
        }
      },
      "aggs": {
        "tops": {
          "top_hits": {
            from: 100,
            size: 50,
            "_source": [
              "id",
              "feed_provider_id"
            ]
          }
        }
      }
    }
  },
  "sort": [
    {
      "instant_book": {
        "order": "desc"
      }
    }
  ]
}

With Search on python: The problem I'm facing with this search, first time the search gets the Aggregated data along with Hits data but for next calling with scroll id it is not returning the Aggregated data only showing the Hits data.

if index_name is not None and doc_type is not None and body is not None:
   es = init_es()
   page = es.search(index_name,doc_type,scroll = '30s',size = 10, body = body)
   sid = page['_scroll_id']
   scroll_size = page['hits']['total']

   # Start scrolling
   while (scroll_size > 0):

       print("Scrolling...")
       page = es.scroll(scroll_id=sid, scroll='30s')
       # Update the scroll ID
       sid = page['_scroll_id']

       print("scroll id: " + sid)

       # Get the number of results that we returned in the last scroll
       scroll_size = len(page['hits']['hits'])
       print("scroll size: " + str(scroll_size))

       print("scrolled data :" )
       print(page['aggregations'])

With Elasticsearch-DSL on python: With this approach I'm struggling to select the _source fields names like id and feed_provider_id on the second aggs i.g tops->top_hits

es = init_es()
    s = Search(using=es, index=index_name,doc_type=doc_type)

    s.aggs.bucket('aggs_by_feed', 'terms', field='feed').metric('top','top_hits',field = 'id')
    response = s.execute()
    print('Hit........')
    for hit in response:
        print(hit.meta.score, hit.feed)
    print(response.aggregations.aggs_by_feed)
    print('AGG........')
    for tag in response.aggregations.aggs_by_feed:
        print(tag)

So my question is

Is it not possible to get data using from and size field on for the aggregated query above from=100?

if it is possible then please give me a hint with normal elasticsearch way or elasticsearch-dsl python way as I am not well known with elasticsearch-dsl and elasticsearch bucket, matric etc.

Some answer on SO told to use partition but I don't know how to use it on my scenario How to control the elasticsearch aggregation results with From / Size?

Some others says that this feature is not currently supported by ES (currently on feature request). If that's not possible, what else can be done in place of grouping in Solr?

A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103
  • Possible duplicate of [Aggregation + sorting +pagination in elastic search](https://stackoverflow.com/questions/27776582/aggregation-sorting-pagination-in-elastic-search) – Özgür Yalçın Mar 10 '19 at 02:18

0 Answers0