# How to edit a ES query in JAVA

**URL:** <https://discuss.elastic.co/t/how-to-edit-a-es-query-in-java/122073>\
**Category:** Elasticsearch\
**Created:** [March 1, 2018, 1:28pm UTC](https://discuss.elastic.co/t/how-to-edit-a-es-query-in-java/122073 "2018-03-01T13:28:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![joker](https://avatars.discourse-cdn.com/v4/letter/j/5f9b8f/32.png) [@joker](https://discuss.elastic.co/u/joker)\
**Post date:** [March 1, 2018, 1:28pm UTC](https://discuss.elastic.co/t/how-to-edit-a-es-query-in-java/122073/1 "2018-03-01T13:28:47Z")

</div>

Can we edit a ES query in jAVA ? like removing some condition, modifying it, etc.

Thanks.

---

<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:** [March 1, 2018, 2:38pm UTC](https://discuss.elastic.co/t/how-to-edit-a-es-query-in-java/122073/2 "2018-03-01T14:38:39Z")

</div>

I don't understand. What kind of "query" are you thinking about?  
May be share some code/examples with what you have in mind.

---

<div class="post-metadata">

**Author:** ![joker](https://avatars.discourse-cdn.com/v4/letter/j/5f9b8f/32.png) [@joker](https://discuss.elastic.co/u/joker)\
**Post date:** [March 1, 2018, 4:54pm UTC](https://discuss.elastic.co/t/how-to-edit-a-es-query-in-java/122073/3 "2018-03-01T16:54:24Z")

</div>

I have a already build query(ie. a variable of type QueryBuilder) now I want to edit this query, to be precise this query has 3 "must" conditions and I want one of those mus to be removed from query. But in general is there way to edit a query after it has been build or like change order of conditions, etc. I googled but didn't find anything related.

> PS : I think user should be given full ability to control query even after it has been build, right ? UPDATE : I think I was wrong.

Thanks.

---

<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:** [March 1, 2018, 5:20pm UTC](https://discuss.elastic.co/t/how-to-edit-a-es-query-in-java/122073/4 "2018-03-01T17:20:22Z")

</div>

I don't think you can.

You should just not add the must condition you want in the first place.

---

<div class="post-metadata">

**Author:** ![joker](https://avatars.discourse-cdn.com/v4/letter/j/5f9b8f/32.png) [@joker](https://discuss.elastic.co/u/joker)\
**Post date:** [March 1, 2018, 5:24pm UTC](https://discuss.elastic.co/t/how-to-edit-a-es-query-in-java/122073/5 "2018-03-01T17:24:19Z")

</div>

Yeah, but I am working on existing codebase and solving a bug requires this thing. Thanks, for help though.

---

<div class="post-metadata">

**Author:** ![joker](https://avatars.discourse-cdn.com/v4/letter/j/5f9b8f/32.png) [@joker](https://discuss.elastic.co/u/joker)\
**Post date:** [March 1, 2018, 7:32pm UTC](https://discuss.elastic.co/t/how-to-edit-a-es-query-in-java/122073/6 "2018-03-01T19:32:48Z")

</div>

So, I removed unwanted must field and taking this new query as skeleton and than modifying this query by copying first into another `QueryBuilder` variable(I assign as `QueryBuilder newQuery = oldQuery;` than modify `newQuery`) but it is getting copied as refrence, any idea why so ?

---

<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:** [March 29, 2018, 7:33pm UTC](https://discuss.elastic.co/t/how-to-edit-a-es-query-in-java/122073/7 "2018-03-29T19:33:11Z")

</div>

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