Aggregating data from child documents in has_child query


(Wojciech Durczyński) #1

Hello.

I'd like to search all parent documents that have child documents in
index, but also would like to retrieve aggregated data about child
documents for found parents.

For example: every child document has price defined as a field and I'd
like to query parent documents that have any children and in search
results I'd like to receive also minimum price value for every parent
(aggregated from this parent's children).

I tried:

  • statistical facet with child scope, but it returns global minimum
    price (not in context of parent)
  • terms facet with script that was concatenating parent id with price
    and from results of this facet I was able to aggregate minimum prices
    for each parent
  • histogram script facet but keys can only be numbers (not parent ids)
    and count can only be total/mean of values and not minimum

What is the best way to achieve desired functionality?

Regards
Wojciech Durczyński


Aggregating child documents in has_child query
(Wojciech Durczyński) #2

One more thing: I cannot add minimum price as a field in parent
document, because children are filtered using various conditions.

On Feb 16, 4:35 pm, Wojciech Durczyński
wojciech.durczyn...@comarch.com wrote:

Hello.

I'd like to search all parent documents that have child documents in
index, but also would like to retrieve aggregated data about child
documents for found parents.

For example: every child document has price defined as a field and I'd
like to query parent documents that have any children and in search
results I'd like to receive also minimum price value for every parent
(aggregated from this parent's children).

I tried:

  • statistical facet with child scope, but it returns global minimum
    price (not in context of parent)
  • terms facet with script that was concatenating parent id with price
    and from results of this facet I was able to aggregate minimum prices
    for each parent
  • histogram script facet but keys can only be numbers (not parent ids)
    and count can only be total/mean of values and not minimum

What is the best way to achieve desired functionality?

Regards
Wojciech Durczyński


(Shay Banon) #3

If I understood correctly, and you want to get facets per parent, then you can't do it.
On Wednesday, February 16, 2011 at 5:52 PM, Wojciech Durczyński wrote:

One more thing: I cannot add minimum price as a field in parent
document, because children are filtered using various conditions.

On Feb 16, 4:35 pm, Wojciech Durczyński
wojciech.durczyn...@comarch.com wrote:

Hello.

I'd like to search all parent documents that have child documents in
index, but also would like to retrieve aggregated data about child
documents for found parents.

For example: every child document has price defined as a field and I'd
like to query parent documents that have any children and in search
results I'd like to receive also minimum price value for every parent
(aggregated from this parent's children).

I tried:

  • statistical facet with child scope, but it returns global minimum
    price (not in context of parent)
  • terms facet with script that was concatenating parent id with price
    and from results of this facet I was able to aggregate minimum prices
    for each parent
  • histogram script facet but keys can only be numbers (not parent ids)
    and count can only be total/mean of values and not minimum

What is the best way to achieve desired functionality?

Regards
Wojciech Durczyński


(srrin) #4

Hi Shay,
Do you have any plan for this feature to be incorporated in upcoming versions?

Thanks
-SRR


(Shay Banon) #5

No, no direct plan, mainly because its not simple (/possible) to do it in a very efficient manner when using child / parent. You might need to change the model to support what you want.
On Wednesday, March 16, 2011 at 3:11 PM, srrIN wrote:

Hi Shay,
Do you have any plan for this feature to be incorporated in upcoming
versions?

Thanks
-SRR

--
View this message in context: http://elasticsearch-users.115913.n3.nabble.com/Aggregating-data-from-child-documents-in-has-child-query-tp2510238p2688162.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.


(system) #6