# Auto Filter by Brand

**URL:** <https://discuss.elastic.co/t/auto-filter-by-brand/219097>\
**Category:** Elasticsearch\
**Created:** [February 13, 2020, 12:07am UTC](https://discuss.elastic.co/t/auto-filter-by-brand/219097 "2020-02-13T00:07:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cannon\_Moyer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cannon_moyer/32/46269_2.png) [@Cannon\_Moyer](https://discuss.elastic.co/u/Cannon_Moyer)\
**Post date:** [February 13, 2020, 12:07am UTC](https://discuss.elastic.co/t/auto-filter-by-brand/219097/1 "2020-02-13T00:07:41Z")

</div>

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"
}

```

}

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 12, 2020, 12:07am UTC](https://discuss.elastic.co/t/auto-filter-by-brand/219097/2 "2020-03-12T00:07:41Z")

</div>

Closed on March 12, 2020, 12:07am UTC

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