Guy Bowden
Guy Bowden

Reputation: 5107

How to add an OR filter around a nested query with elasticsearch-dsl

I have a nested filter that looks like this:

search = search.filter(
                'nested', 
                path=path, 
                filter=F('bool', must=queries),
                inner_hits={'sort': ['p', 'd']}
            )

I'd like to add an OR filter around the whole thing. So it either matches X OR this nested query.

I am using ES 1.7

Upvotes: 1

Views: 679

Answers (1)

Guy Bowden
Guy Bowden

Reputation: 5107

A little more perseverance got me this:

search = search.filter(
                'or',
                [F(
                    'nested',
                    path=path,
                    filter=F('bool', must=queries),
                    inner_hits={'sort': ['p', 'd']}
                ), F('bool', must=or_queries)]
            )

Which seems to do the trick..

Upvotes: 1

Related Questions