Compound query with inversed (exclude) logic


(Andrew Butenko) #1

Hi,
I use Dot.Net Elastic Client v5 to build original query dynamically based on user choice.

For that reason I use QueryContainer with different types of query. It works fine for inclusion filter logic (condition1 + condition2+ etc.).

Before sending request to the ElasticSearch server I would like to apply inverse filter (if user clicked exclude in my UI) which should inverse all combined conditions in one exclude statement. As I understand, I have to use BoolQuery MustNot. so, my pseudo code looks like:

QueryContainer qc = new QueryContainer();
///...populate all conditions
///check exclude option is chousen by user and inverse it
if (query.Inversed.HasValue && query.Inversed.Value == true)
{
qc = new BoolQuery()
{
MustNot = new QueryContainer[] { qc }
};
}
///send request to ElasticSearch server...

For example, all query result has 100 hits, with all conditions it should return 10 items. But with exclude option it should be 90 items.
Unfortunatly my query returns 0 hits with MustNot option,

Could you please advise how to implement inverse logic in my case?


(Andrew Butenko) #2

Seems like nobody knows how to implement inverse logic by one click.
Any idea?


(system) #3

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