Nested Query score_mode min?


(Zachary Tong) #1

It appears "min" is not a viable option for the score_mode on nested
queries. Would it be possible to add this? Or another way to "fake" the
same result?

I have a nested document structure, where a single "Product" can contain
multiple "Vendors" who sell the product. Each vendor has a "productCost"
property which is the price of the product.

I'm attempting to sort these by price in Ascending order. To accomplish
this with the nested documents, I'm applying a custom_score to each
"Vendor" nested document, where the score == price. I then sort the entire
set by the _score ascending.

This works mostly ok. Search results are sorted by price ascending.
However, since the score_mode on nested cannot do "min", products with
multiple vendors can be mis-sorted ($10 vendor and $100 vendor will cause
the parent doc to sort incorrectly, since both Avg and Max return too high
of a value)

I realize I can denormalize my fields and make the parent doc contain a
"lowestPrice" field which is kept current. If there is no other way to
perform this query I'll use this approach.

Thanks,
-Zach


(Igor Motov) #2

The simplest solution that comes to mind is to use custom_score with score
== -price.

On Thursday, August 2, 2012 2:15:11 PM UTC-4, Zachary Tong wrote:

It appears "min" is not a viable option for the score_mode on nested
queries. Would it be possible to add this? Or another way to "fake" the
same result?

I have a nested document structure, where a single "Product" can contain
multiple "Vendors" who sell the product. Each vendor has a "productCost"
property which is the price of the product.

I'm attempting to sort these by price in Ascending order. To accomplish
this with the nested documents, I'm applying a custom_score to each
"Vendor" nested document, where the score == price. I then sort the entire
set by the _score ascending.

This works mostly ok. Search results are sorted by price ascending.
However, since the score_mode on nested cannot do "min", products with
multiple vendors can be mis-sorted ($10 vendor and $100 vendor will cause
the parent doc to sort incorrectly, since both Avg and Max return too high
of a value)

I realize I can denormalize my fields and make the parent doc contain a
"lowestPrice" field which is kept current. If there is no other way to
perform this query I'll use this approach.

Thanks,
-Zach


(Zachary Tong) #3

Doh, what a simple solution. Thanks, worked great!

-Zach

On Thursday, August 2, 2012 5:17:54 PM UTC-4, Igor Motov wrote:

The simplest solution that comes to mind is to use custom_score with score
== -price.

On Thursday, August 2, 2012 2:15:11 PM UTC-4, Zachary Tong wrote:

It appears "min" is not a viable option for the score_mode on nested
queries. Would it be possible to add this? Or another way to "fake" the
same result?

I have a nested document structure, where a single "Product" can contain
multiple "Vendors" who sell the product. Each vendor has a "productCost"
property which is the price of the product.

I'm attempting to sort these by price in Ascending order. To accomplish
this with the nested documents, I'm applying a custom_score to each
"Vendor" nested document, where the score == price. I then sort the entire
set by the _score ascending.

This works mostly ok. Search results are sorted by price ascending.
However, since the score_mode on nested cannot do "min", products with
multiple vendors can be mis-sorted ($10 vendor and $100 vendor will cause
the parent doc to sort incorrectly, since both Avg and Max return too high
of a value)

I realize I can denormalize my fields and make the parent doc contain a
"lowestPrice" field which is kept current. If there is no other way to
perform this query I'll use this approach.

Thanks,
-Zach


(system) #4