0
votes

I am trying to implement paging to fetch results in chunk from Terms aggregation result. But it seems Terms aggregation does not support 'From(..)' method.

Below is my Elastic Search Query in NEST -

ISearchResponse<dynamic> bResponse = ObjElasticClient.Search<dynamic>(s => s
                                             .Filter(FQuery)
                                             .Size(10)                                                                                                    
                                             .Index(elastic_indexname)
                                             .Source(false)
                                             .AllTypes()
                                             .Aggregations(a => a
                                                 .Terms(aggGroupByCDMInvoiceID, t => t
                                                          .Field("CDM_INVOICE_ID")
                                                          .Size(100)                                                                                                            
                                                          .Aggregations(innerAgg => innerAgg
                                                          .TopHits(aggLatestDocVersion, th => th
                                                          .Size(1)
                                                          .Source(false)
                                                          .Sort(x => x.OnField("VERSION").Descending())
                                                          )
                                                         )
                                                        )
                                                       )
                                                      );

I have set size 100 for terms aggregation and now implementing paging. But Terms aggregation does not accept 'From(..)' method.

Is there any alternate solution?

Thanks, Sameer

1
I don't think it's possible stackoverflow.com/questions/27776582/… - Rob

1 Answers

0
votes

Maybe you could order the terms differently and then page by filtering on index?

As per the documentation:

Change ordering:

{
    "aggs" : {
        "genders" : {
            "terms" : {
                "field" : "gender",
                "order" : { "_term" : "asc" }
            }
        }
    }
}

And then filter:

{
    "aggs" : {
        "tags" : {
            "terms" : {
                "field" : "tags",
                "include" : ".*sport.*",
                "exclude" : "water_.*"
            }
        }
    }
}

Alternatively you could reverse the order and then use min_doc_count with the doc count from the previous result for paging:

{
    "aggs" : {
        "tags" : {
            "terms" : {
                "field" : "tags",
                "min_doc_count": 10
            }
        }
    }
}