How to query pass optional attribute template variable in elastic Lucene query?

Hi Community,

Is there a way to pass the optional attribute variable in the elastic Lucene query?

Example like:
In elastic Lucene query: user:$user AND service:$service

Here it shows records that have user and service fields exis with values I filter, but my requirement is user attribute may or may not exist, and if exits I want to filter using the value using template $user.

So is there a way to achieve such use case? Please help.

Thank you in advance.

gentle bump!

want to check if anyone has a solution for this.