Suggester Context

We have an index that uses an Autocomplete Suggester. The index definition is:

.Completion(c => c.Analyzer("standard")
.Contexts(ctx=> ctx
.Category(x => x.Name("flags").Path(p => p.AvailableCategories))

As you can see we have 2 category contexts.

When querying for example:

var searchResponse = await client.SearchAsync(s => s
.Source(sf => sf.Excludes(e => e.Field("geometry")))
//.Query(q => q
//.Bool(bq => bq.Filter(filters)))
.Suggest(ss => ss
.Completion("suggestions", c => c
.Contexts(ctxs=>ctxs.Context("flags", ctx => ctx.Context(flags)).Context("country", ctx => ctx.Context(country)))


Elasticsearch uses an OR operation. i.e. it will return results if either is true.

Is there any way to make the operation an AND i.e.BOTH contexts must be true in order for the document to be matched?

Many thanks

No that's not possible. The contexts are additive, you can boost values that have multiple contexts (by adding more context values to your query) but you cannot enforce an AND between the context values. If you want to only match suggestions with multiple contexts you can create a composite contexts flags-and-country and set the context values at index time as the combinations of all flags and countries for the document.

Many Thanks.

We already did that but wondered if the AND was a possibility.

Many Thanks.

We already did that but wondered if that was a possibility.



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