# How to prevent must clause not being added into bool query if it has null value in Java API Client

**URL:** <https://discuss.elastic.co/t/how-to-prevent-must-clause-not-being-added-into-bool-query-if-it-has-null-value-in-java-api-client/359729>\
**Category:** Elasticsearch\
**Created:** [May 17, 2024, 5:42pm UTC](https://discuss.elastic.co/t/how-to-prevent-must-clause-not-being-added-into-bool-query-if-it-has-null-value-in-java-api-client/359729 "2024-05-17T17:42:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![PodarcisMuralis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/podarcismuralis/32/122606_2.png) [@PodarcisMuralis](https://discuss.elastic.co/u/PodarcisMuralis)\
**Post date:** [May 17, 2024, 5:42pm UTC](https://discuss.elastic.co/t/how-to-prevent-must-clause-not-being-added-into-bool-query-if-it-has-null-value-in-java-api-client/359729/1 "2024-05-17T17:42:15Z")

</div>

I have a simple SearchRequest using the new elasticsearch Java API Client Library.

```auto
return SearchRequest.of(sr -> sr
                .index("myIndex")
                .query(q -> q
                        .bool(b -> b                                                          
                                .must(myCustomBoolQuery1)
                                .must(myCustomRangeQuery1)
                                .must(myCustomMatchQuery1)
                                
                        )
                )

```

How can I prevent adding **myCustomRangeQuery1** if it is null?
