# How to query on {brand} and/or {category string} efficiently?

**URL:** https://discuss.elastic.co/t/how-to-query-on-brand-and-or-category-string-efficiently/51117
**Category:** Elasticsearch
**Created:** [May 27, 2016, 6:51am UTC](https://discuss.elastic.co/t/how-to-query-on-brand-and-or-category-string-efficiently/51117 "2016-05-27T06:51:40Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![mgoslett](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@mgoslett](https://discuss.elastic.co/u/mgoslett)
#### Post date: [May 27, 2016, 6:51am UTC](https://discuss.elastic.co/t/how-to-query-on-brand-and-or-category-string-efficiently/51117/1 "2016-05-27T06:51:40Z")

</div>

I'm looking for assistance in searching our product index for terms such as:  
Men's Shoes  
Nike Men's Shoes  
Men's Nike Shoes  
Shoes

For this specific query, the following fields are applicable:  
brand\_exact (non-tokenized, lowercase, asciifolding)  
brand\_t (tokenized with whitespace tokenizer, lowercase, asciifolding)  
brand\_ngram (edge n-gram 3 to 8 tokenizer, lowercase, asciifolding)  
categories\_t (english analyzer)

An example document might look like:  
brand\_exact: nike  
brand\_t: nike  
brand\_ngram, [nik, nike]  
categories\_t [men's shoes]

I've tried various combinations of matching using the bool filter and am able to produce relevant results; but I land up with too many irrelevant results at the end and am looking to improve this query or cutoff results.  
A search on "Men's Shoes" brings up all men's shoes first, and then all other men's products because of the categories\_t token match on 'men'.

Does anyone have any suggestions for how I could improve this?

---

<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: [July 5, 2017, 10:48pm UTC](https://discuss.elastic.co/t/how-to-query-on-brand-and-or-category-string-efficiently/51117/2 "2017-07-05T22:48:37Z")

</div>


