Is it possible to do a BucketSort of an aggregation based on score rather than on document count?

Hello,

is it possible to do a BucketSort of an aggregation based on score rather than on document count (using Flunet interface of Nest 6.5)?

E.g., like in following query where I want to get all directors that are spelled similarly to "Scorsese". All elements within each bucket should have the same score, since the query only contains the field name "Director" that is also used for aggregation.

this.elasticClient
                .SearchAsync<Movies>(
                    s => s
                        .Index(Titles)
                        .Size(0)
                        .Aggregations(a => a
                            .Terms("directors", t => t
                                .Field(f => f
                                    .Director
                                    .Suffix("keyword"))
                                .Size(maxResults)))
                        .Query(q => q
                            .Bool(b =>
                                b = b.Must(
                                   must =>
                                        must.Match(m => m
                                            .Field(f => f.Director)
                                            .Query("Scorsese")
                                            .Fuzziness(Fuzziness.Auto)
                                        )))));

The output is correct but the ordering is based on the document count. As long as one is looking for "Scorsese" everything is fine but if you are looking for someone spelled similarly you would still get "Scorsese" as top hit even if you spelled the name you are looking for correctly.

If I do a BucketSort on score I get an error response telling me that this is not allowed. If there is no way to sort the buckets on their score then my whole design is flawed. :anguished:

Thanks,

Art

Maybe it's possible to just select the Director field and its score and remove redundant hits in the response, like here:

unfortunately I cannot see how to do this via the Fluent interface of Nest 6.5.

I got this:

.SearchAsync<Movies>(
                    s => s
                        .Index(Titles)
                        .Size(10000)
                        .Aggregations(a => a
                            .Nested("top", n => n
                                .Path(p => p
                                    .Director.Suffix("keyword"))
                                .Aggregations(na => na
                                    .TopHits("th", th => th.Size(100)
                                        .Sort( sort => sort
                                            .Descending(SortSpecialField.Score))))))
                        .Query(q => q
                            .Bool(b =>
                                b = b.Must(
                                   must =>
                                        must.Match(m => m
                                            .Field(f => f.Director)
                                            .Query("Scorsese")
                                            .Fuzziness(Fuzziness.Auto)
                                        )))));

but that doesn't work.

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