# How can I filter Suggestions

**URL:** <https://discuss.elastic.co/t/how-can-i-filter-suggestions/210577>\
**Category:** Elasticsearch\
**Created:** [December 4, 2019, 5:44pm UTC](https://discuss.elastic.co/t/how-can-i-filter-suggestions/210577 "2019-12-04T17:44:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![athir.gillani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/athir.gillani/32/47708_2.png) [@athir.gillani](https://discuss.elastic.co/u/athir.gillani)\
**Post date:** [December 4, 2019, 5:44pm UTC](https://discuss.elastic.co/t/how-can-i-filter-suggestions/210577/1 "2019-12-04T17:44:20Z")

</div>

I have an index for items, and I am making a suggest query on top of it like this below. It is working fine, but I want to include the item in suggestions list only if it is active and not sold. I am trying to do it through context, but not able to add to the context a boolean field, I already have added a context for geo-point to the schema and data, but not sure

1. how can I add a boolean context,
2. And how can I make a and condition for 2 context check, as I have 2 fields for active and sold.

Kindly help if you want experience with this, thanks.

{  
"suggest": {  
"name": {  
"prefix": "something",  
"completion": {  
"field": "name.completion",  
"fuzzy": {  
"fuzziness": 1,  
"transpositions": true,  
"min\_length": 3,  
"prefix\_length": 1,  
"unicode\_aware": false,  
"max\_determinized\_states": 10000  
}  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![athir.gillani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/athir.gillani/32/47708_2.png) [@athir.gillani](https://discuss.elastic.co/u/athir.gillani)\
**Post date:** [December 5, 2019, 12:51pm UTC](https://discuss.elastic.co/t/how-can-i-filter-suggestions/210577/2 "2019-12-05T12:51:01Z")

</div>

Trying to add boolean context, I found you can only add contexts of type "geo\_point" and "category". I am trying to add category context with boolean value, but it is returning an error that boolean can not a value for category context, but as my understanding I can put boolean values for a category context.

I am new to ES, please correct me if I am wrong, and describe the correct way of making a check on active/inactive with suggestions on name field of an item.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [December 6, 2019, 12:11pm UTC](https://discuss.elastic.co/t/how-can-i-filter-suggestions/210577/3 "2019-12-06T12:11:43Z")

</div>

how about just having a string `"true"` or `"false"` instead of a boolean in the category context?

---

<div class="post-metadata">

**Author:** ![athir.gillani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/athir.gillani/32/47708_2.png) [@athir.gillani](https://discuss.elastic.co/u/athir.gillani)\
**Post date:** [December 8, 2019, 5:54pm UTC](https://discuss.elastic.co/t/how-can-i-filter-suggestions/210577/4 "2019-12-08T17:54:28Z")

</div>

how can I convert boolean to string to fill in context. The index is primarily structured to make queries for list of items, where each item has active status as boolean. I want to use the same field in the suggestion context to only suggest items which are active. Your idea can work only if, I convert the active field in the actual record also, which is then used to fill in the context.

---

<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:** [January 5, 2020, 5:54pm UTC](https://discuss.elastic.co/t/how-can-i-filter-suggestions/210577/5 "2020-01-05T17:54:35Z")

</div>

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