How can I filter Suggestions

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

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.

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

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.

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