reactivesearch icon indicating copy to clipboard operation
reactivesearch copied to clipboard

[Lists] Count top-level documents instead of nested documents when using nestedField

Open WhoisDavid opened this issue 5 years ago • 1 comments

Affected Projects React / All

Is your feature request related to a problem? Please describe. Nested fields count is based on nested documents. Would be great to have a way to switch it to count on the top-level document. This would apply to all lists with a count.

Example:

bookshelf1.books : [
 { book1: {author: "John Doe} },
 { book2: {author: "Rick Doe} },
 { book3: {author: "John Doe} },
],
bookshelf2.books : [
 { book1:  {author: "Jane Doe} },
 { book2:  {author: "Jane Doe} },
 { book3:  {author: "John Doe} },
]

Currently, if filtering on bookshelf.books.author, one would get the following counts on "books":

John Doe    3
Jane Doe    2
Rick Doe    1

would be great to be able to switch to a count on "bookshelf":

John Doe    2
Jane Doe    1
Rick Doe    1

Ultimately, the results returns (unless using inner_hits) are based on the top-level document (bookshelf) in this example. Therefore, I think it feels more natural to display the count on them in many cases.

Describe the solution you'd like One way would be to add a boolean prop e.g reverseNestedCount which would then change the aggregation method. To my knowledge there is currently no way to modify the aggregation used for counting but I could be wrong (?).

In ES, this would be achieved using a reverse nested aggregation.

Describe alternatives you've considered I guess the alternative would be to write a component from scratch

WhoisDavid avatar Mar 23 '20 09:03 WhoisDavid

Did you found a workaround or fix for this @WhoisDavid?

royduin avatar Oct 29 '20 16:10 royduin