# How to create Java query for a script

**URL:** <https://discuss.elastic.co/t/how-to-create-java-query-for-a-script/181162>\
**Category:** Elasticsearch\
**Created:** [May 15, 2019, 11:14am UTC](https://discuss.elastic.co/t/how-to-create-java-query-for-a-script/181162 "2019-05-15T11:14:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Santosh\_Pandey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/santosh_pandey/32/46221_2.png) [@Santosh\_Pandey](https://discuss.elastic.co/u/Santosh_Pandey)\
**Post date:** [May 15, 2019, 11:14am UTC](https://discuss.elastic.co/t/how-to-create-java-query-for-a-script/181162/1 "2019-05-15T11:14:15Z")

</div>

I have 2 attributes: price1 and price2.  
I need to filter the result if price1 \< price2

How to create Java code for it. I have written the following:  
QueryBuilders.boolQuery()  
.filter(QueryBuilders.scriptQuery("doc['lowestOurPrice'].value \< doc['lowestBasePrice'].value"));

scriptQuery accepts Script object. How to create Script object with my query?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 12, 2019, 11:14am UTC](https://discuss.elastic.co/t/how-to-create-java-query-for-a-script/181162/2 "2019-06-12T11:14:18Z")

</div>

Closed on June 12, 2019, 11:14am UTC

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