# Equivalent JAVA code for the below query

**URL:** <https://discuss.elastic.co/t/equivalent-java-code-for-the-below-query/175149>\
**Category:** Elasticsearch\
**Created:** [April 3, 2019, 9:38am UTC](https://discuss.elastic.co/t/equivalent-java-code-for-the-below-query/175149 "2019-04-03T09:38:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harsha\_Yerasi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/harsha_yerasi/32/42985_2.png) [@Harsha\_Yerasi](https://discuss.elastic.co/u/Harsha_Yerasi)\
**Post date:** [April 3, 2019, 9:38am UTC](https://discuss.elastic.co/t/equivalent-java-code-for-the-below-query/175149/1 "2019-04-03T09:38:06Z")

</div>

Please help me with the equivalent java code to this search

`GET my_index/_search { "query": { "bool": { "must": { "nested": { "path": "workexperience", "query": { "terms": { "workexperience.title": ["1"] } } } } } } }`

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 3, 2019, 5:24pm UTC](https://discuss.elastic.co/t/equivalent-java-code-for-the-below-query/175149/2 "2019-04-03T17:24:02Z")

</div>

Please format your code, logs or configuration files using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and not the citation button. It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

This is the icon to use if you are not using markdown format:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e6e239431ec2d71cbf1beef741f2e93e7cc762c.jpg)

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.  
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.  
Please update your post.

Also what did you try so far?

---

<div class="post-metadata">

**Author:** ![Harsha\_Yerasi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/harsha_yerasi/32/42985_2.png) [@Harsha\_Yerasi](https://discuss.elastic.co/u/Harsha_Yerasi)\
**Post date:** [April 8, 2019, 5:48am UTC](https://discuss.elastic.co/t/equivalent-java-code-for-the-below-query/175149/3 "2019-04-08T05:48:01Z")

</div>

Hi dadoonet,

I have formatted as per your suggestion.

I was able to solve the problem after some googling thank you.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 8, 2019, 7:20am UTC](https://discuss.elastic.co/t/equivalent-java-code-for-the-below-query/175149/4 "2019-04-08T07:20:50Z")

</div>

May be share your solution here?

---

<div class="post-metadata">

**Author:** ![Harsha\_Yerasi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/harsha_yerasi/32/42985_2.png) [@Harsha\_Yerasi](https://discuss.elastic.co/u/Harsha_Yerasi)\
**Post date:** [April 8, 2019, 7:25am UTC](https://discuss.elastic.co/t/equivalent-java-code-for-the-below-query/175149/5 "2019-04-08T07:25:01Z")

</div>

```
QueryBuilders.boolQuery()
                    .must(QueryBuilders.nestedQuery("title",
                            QueryBuilders.termsQuery(
                                    "title" + "." + "workexperience",
                                    List.of("1"),
                            ScoreMode.Avg));

```

The above is the equivalent Java code, which is working fine for me.

---

<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:** [May 6, 2019, 7:25am UTC](https://discuss.elastic.co/t/equivalent-java-code-for-the-below-query/175149/6 "2019-05-06T07:25:13Z")

</div>

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