Conditional queries(aka if…else) are not supported directly in elasticsearch DSL, you need to do this conditional logic in your app-server which is firing the ES queries.
Please refer to the conditional clause in elasticsearch for more info.
CLICK HERE to find out more related problems solutions.