elasticsearch - Wrong count for nested facets -


i'm building search products , variants. 1 product can have many nested variants. example: 1 t-shirt can in 2 variants, white 50 euros , green 60 euros. it's still same product , should displayed once on results page.

this mapping:

{"product" => { "properties" => {"vendor_variants" => {"type" => "nested"}}}} 

and query i'm doing:

"query" => {     "filtered" => {       "query" => {         "match_all" => {}       },       "filter" => {         "bool" => {           "must" => [             {               "terms" => {                 "categories" => [122]               }             }           ]         }       }     }   },   "facets" => {     "brand" => { "terms" => {"field" => "filter_brand"} },     "price_range" => {       "nested" => "vendor_variants",       "range" => { "field" => "price", "ranges" => [ {"to" => 2000}, {"from" => 2000, "to" => 5000} ]       }     }   } 

this query produces 172 results. facets price ranges wrong. example returns 20-50 euro range there 422 results. believe it's because counts every single nested vendor_variants document. it's not need, need count main product documents.

what wrong query?

figured out. in mapping nested document, had add "include_in_parent" => true


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -