Auto Filter by Brand

I'm running ES 7.3.

have a query where a user can search a list of machines by two fields, brand and name . I am using an ngram search on the name fields so that similar matches will be found. I want my query to work in such a way that if there is a match on the brand.name field, I would like to automatically filter by that matched brand. Say I have a brand of "Walmart" and someone types "Walmart bicycle". I would want that query to ensure that all returned records have a brand of "Walmart". Here is my current query which allows for manual filtering but won't auto select filters. Will this require an original query on a list of Brands and then another query on the actual products containing the filter if it was found?

{
query: {

function_score: {
    query:{
        bool: {
            must: {
                    multi_match:{
                         fields: ['name^10', 'name.ngram^5',"brand.name^10", "brand.name.ngram^5"],
                         type: "most_fields", #was bool_prefix
                         query: "#{params[:q]}",
                     }
            },
            should: ranges[:must],
            filter:{
                bool:{
                    must: filters
                 }
            }
        }
},field_value_factor:{
    field: "popularity",
    modifier: "log1p",
    factor: 1
},
boost_mode: "sum"
}

}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.