Hi,

Currently, we have data in 2 collections - Product and its associated offers

offer collection data format
{
                "id": "OFF1",
                "p_id_ss": ["P1", "P2", "P3"......] // upto 6K product ids
in certain cases
                "o_type_s": "50% Off Offer"               // other 20 fields

}, {
                "id": "OFF2",
                "p_id_ss": ["P2", "P3"......]
                "o_type_s": "20% Off On XYZ Card",
    // other 20 fields

}and so on till 50k documents.................................

Product data format
{
                "id": "P1",
                "o_id_ss": ["OFF1", "OFF2", "OFF3"]
                "p_name_s": "Men's Nike shoes",
                 "p_category_s": "Shoe"               // other 50 fields

}, {
                "id": "P2",
                "o_id_ss": ["OFF3", "OFF4", "OFF5"]
               "p_name_s": "Women dress,
                "p_category_s": "Dress"
               // other 50 fields
}
and so on till 10k documents.................................

In order to calculate facets at offer Level, we are using the below query
(Json facet + Aggregate Functions), which works fine.
/select?q=*:*&rows=10&facet=true&facet.mincount=1&json.facet={"p_category":{"type":"terms","field":"p_category","domain":{"excludeTags":["p_id_s","o_id_ss","p_category"]},"facet":{"count":"unique(o_id_ss)"}}}&fq=p_id_s:P1

*But, lets there is scenario where there is filter on offer id, this query
is not returning correct facet count.*

select?q=*:*&rows=10&facet=true&facet.mincount=1&json.facet={"p_category_s":{"type":"terms","field":"p_category_s","domain":{"excludeTags":["p_id_s","o_id_ss","p_category_s"]},"facet":{"count":"unique(o_id_ss)"}}}&fq=o_id_ss:OFF-1

The count that is coming is more than 1 (as we are applying a filter on one
offer id). But, since the 'o_id_ss' is a multi-valued field, it is giving a
count based upon all the values in that field.

Please suggest how to tune this query or there is another approach to solve
this requirement to fetch facet data for product fields at offer level.

Notes:

• One offer can be tagged to multiple products.
• One product can be tagged to multiple offers.

Regards
Kamal

Reply via email to