# How to save Query JSON as it is in an Index?

**URL:** https://discuss.elastic.co/t/how-to-save-query-json-as-it-is-in-an-index/15059
**Category:** Elasticsearch
**Created:** [December 31, 2013, 12:23am UTC](https://discuss.elastic.co/t/how-to-save-query-json-as-it-is-in-an-index/15059 "2013-12-31T00:23:22Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![search](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@search](https://discuss.elastic.co/u/search)
#### Post date: [December 31, 2013, 12:23am UTC](https://discuss.elastic.co/t/how-to-save-query-json-as-it-is-in-an-index/15059/1 "2013-12-31T00:23:22Z")

</div>

I want to save the query JSON as it as in a field in an ES index. I should  
be able to retrieve queries and run it at a later time. I don't need  
features like percolator. I am using Java client to index and retrieve.

What should I do to achieve this?

Thanks.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/a11a80e4-68c1-4e30-8b14-b6296a0f365a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a11a80e4-68c1-4e30-8b14-b6296a0f365a%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Daniel\_Guo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_guo/32/1725_2.png) [@Daniel\_Guo](https://discuss.elastic.co/u/Daniel_Guo)
#### Post date: [December 31, 2013, 6:21am UTC](https://discuss.elastic.co/t/how-to-save-query-json-as-it-is-in-an-index/15059/2 "2013-12-31T06:21:16Z")

</div>

I don't get your point, can you describe more detail?

On Tuesday, December 31, 2013 8:23:22 AM UTC+8, Search User wrote:

> I want to save the query JSON as it as in a field in an ES index. I should  
> be able to retrieve queries and run it at a later time. I don't need  
> features like percolator. I am using Java client to index and retrieve.
> 
> What should I do to achieve this?
> 
> Thanks.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/cd59317e-24a9-4074-af40-fe2439d4bc6e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/cd59317e-24a9-4074-af40-fe2439d4bc6e%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![search](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@search](https://discuss.elastic.co/u/search)
#### Post date: [December 31, 2013, 6:53pm UTC](https://discuss.elastic.co/t/how-to-save-query-json-as-it-is-in-an-index/15059/3 "2013-12-31T18:53:15Z")

</div>

I want to save the queries my users are executing and let them re-run at a  
later time.

Thanks,

On Tuesday, December 31, 2013 1:21:16 AM UTC-5, Daniel Guo wrote:

> I don't get your point, can you describe more detail?
> 
> On Tuesday, December 31, 2013 8:23:22 AM UTC+8, Search User wrote:
> 
> > I want to save the query JSON as it as in a field in an ES index. I  
> > should be able to retrieve queries and run it at a later time. I don't need  
> > features like percolator. I am using Java client to index and retrieve.
> > 
> > What should I do to achieve this?
> > 
> > Thanks.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/28ee8010-df47-489f-90df-07e41d831d42%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/28ee8010-df47-489f-90df-07e41d831d42%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [January 1, 2014, 8:27pm UTC](https://discuss.elastic.co/t/how-to-save-query-json-as-it-is-in-an-index/15059/4 "2014-01-01T20:27:36Z")

</div>

Hey,

you could simply use the toString(), or even better the toXContent()  
representation of a query and store it in another index, when executing  
queries using your java API.

Alternatively you could set the thresholds for the slow index log very log  
and thus log every index operation (this has a performance impact), see

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

--Alex

On Tue, Dec 31, 2013 at 7:53 PM, Search User [feedworks@gmail.com](mailto:feedworks@gmail.com) wrote:

> I want to save the queries my users are executing and let them re-run at a  
> later time.
> 
> Thanks,
> 
> On Tuesday, December 31, 2013 1:21:16 AM UTC-5, Daniel Guo wrote:
> 
> > I don't get your point, can you describe more detail?
> > 
> > On Tuesday, December 31, 2013 8:23:22 AM UTC+8, Search User wrote:
> > 
> > > I want to save the query JSON as it as in a field in an ES index. I  
> > > should be able to retrieve queries and run it at a later time. I don't need  
> > > features like percolator. I am using Java client to index and retrieve.
> > > 
> > > What should I do to achieve this?
> > > 
> > > Thanks.
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/28ee8010-df47-489f-90df-07e41d831d42%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/28ee8010-df47-489f-90df-07e41d831d42%40googlegroups.com)  
> > .
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGCwEM8Ua5bLHhhnf5r2VdL99LDQVbazfu%3DsLK1z\_w8UHn5W4w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM8Ua5bLHhhnf5r2VdL99LDQVbazfu%3DsLK1z_w8UHn5W4w%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Amit\_Soni](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Amit\_Soni](https://discuss.elastic.co/u/Amit_Soni)
#### Post date: [February 3, 2014, 7:44am UTC](https://discuss.elastic.co/t/how-to-save-query-json-as-it-is-in-an-index/15059/5 "2014-02-03T07:44:32Z")

</div>

I have an identical requirement and have a question: if we save the query  
using toXContent() would the same query work fine when the version of  
Elasticsearch changes (say it went through some major version change)?

-Amit.

On Wed, Jan 1, 2014 at 12:27 PM, Alexander Reelsen [alr@spinscale.de](mailto:alr@spinscale.de) wrote:

> Hey,
> 
> you could simply use the toString(), or even better the toXContent()  
> representation of a query and store it in another index, when executing  
> queries using your java API.
> 
> Alternatively you could set the thresholds for the slow index log very log  
> and thus log every index operation (this has a performance impact), see
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/index-modules-slowlog.html#index-slow-log)
> 
> --Alex
> 
> On Tue, Dec 31, 2013 at 7:53 PM, Search User [feedworks@gmail.com](mailto:feedworks@gmail.com) wrote:
> 
> > I want to save the queries my users are executing and let them re-run at  
> > a later time.
> > 
> > Thanks,
> > 
> > On Tuesday, December 31, 2013 1:21:16 AM UTC-5, Daniel Guo wrote:
> > 
> > > I don't get your point, can you describe more detail?
> > > 
> > > On Tuesday, December 31, 2013 8:23:22 AM UTC+8, Search User wrote:
> > > 
> > > > I want to save the query JSON as it as in a field in an ES index. I  
> > > > should be able to retrieve queries and run it at a later time. I don't need  
> > > > features like percolator. I am using Java client to index and retrieve.
> > > > 
> > > > What should I do to achieve this?
> > > > 
> > > > Thanks.
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups  
> > > "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/28ee8010-df47-489f-90df-07e41d831d42%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/28ee8010-df47-489f-90df-07e41d831d42%40googlegroups.com)  
> > > .
> > 
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CAGCwEM8Ua5bLHhhnf5r2VdL99LDQVbazfu%3DsLK1z\_w8UHn5W4w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM8Ua5bLHhhnf5r2VdL99LDQVbazfu%3DsLK1z_w8UHn5W4w%40mail.gmail.com)  
> .
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAAOGaQ%2BC5vKe93gFRu1GnHwhH-P2woRP6yutvChWo%3DSFh3rHsw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAOGaQ%2BC5vKe93gFRu1GnHwhH-P2woRP6yutvChWo%3DSFh3rHsw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [February 3, 2014, 9:11am UTC](https://discuss.elastic.co/t/how-to-save-query-json-as-it-is-in-an-index/15059/6 "2014-02-03T09:11:48Z")

</div>

Hey,

I am not sure I understand your concern. Of course, there is a possibility  
that the toXContent() method possibly changes over versions, but it didnt  
for quite some time (as this would also change the JSON response format)  
and I think it makes sense to be pretty conservative with changes there...

--Alex

On Mon, Feb 3, 2014 at 8:44 AM, Amit Soni [amitsoni29@gmail.com](mailto:amitsoni29@gmail.com) wrote:

> I have an identical requirement and have a question: if we save the query  
> using toXContent() would the same query work fine when the version of  
> Elasticsearch changes (say it went through some major version change)?
> 
> -Amit.
> 
> On Wed, Jan 1, 2014 at 12:27 PM, Alexander Reelsen [alr@spinscale.de](mailto:alr@spinscale.de)wrote:
> 
> > Hey,
> > 
> > you could simply use the toString(), or even better the toXContent()  
> > representation of a query and store it in another index, when executing  
> > queries using your java API.
> > 
> > Alternatively you could set the thresholds for the slow index log very  
> > log and thus log every index operation (this has a performance impact), see
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/index-modules-slowlog.html#index-slow-log)
> > 
> > --Alex
> > 
> > On Tue, Dec 31, 2013 at 7:53 PM, Search User [feedworks@gmail.com](mailto:feedworks@gmail.com) wrote:
> > 
> > > I want to save the queries my users are executing and let them re-run at  
> > > a later time.
> > > 
> > > Thanks,
> > > 
> > > On Tuesday, December 31, 2013 1:21:16 AM UTC-5, Daniel Guo wrote:
> > > 
> > > > I don't get your point, can you describe more detail?
> > > > 
> > > > On Tuesday, December 31, 2013 8:23:22 AM UTC+8, Search User wrote:
> > > > 
> > > > > I want to save the query JSON as it as in a field in an ES index. I  
> > > > > should be able to retrieve queries and run it at a later time. I don't need  
> > > > > features like percolator. I am using Java client to index and retrieve.
> > > > > 
> > > > > What should I do to achieve this?
> > > > > 
> > > > > Thanks.
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > > > To view this discussion on the web visit  
> > > > [https://groups.google.com/d/msgid/elasticsearch/28ee8010-df47-489f-90df-07e41d831d42%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/28ee8010-df47-489f-90df-07e41d831d42%40googlegroups.com)  
> > > > .
> > > 
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/CAGCwEM8Ua5bLHhhnf5r2VdL99LDQVbazfu%3DsLK1z\_w8UHn5W4w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM8Ua5bLHhhnf5r2VdL99LDQVbazfu%3DsLK1z_w8UHn5W4w%40mail.gmail.com)  
> > .
> > 
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CAAOGaQ%2BC5vKe93gFRu1GnHwhH-P2woRP6yutvChWo%3DSFh3rHsw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAOGaQ%2BC5vKe93gFRu1GnHwhH-P2woRP6yutvChWo%3DSFh3rHsw%40mail.gmail.com)  
> .
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGCwEM8NgsaRjQe4od70TVCTq1g%3DKhSr-tFW%3D-bqZPqv%3D8gSiA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM8NgsaRjQe4od70TVCTq1g%3DKhSr-tFW%3D-bqZPqv%3D8gSiA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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: [July 6, 2017, 1:53am UTC](https://discuss.elastic.co/t/how-to-save-query-json-as-it-is-in-an-index/15059/7 "2017-07-06T01:53:14Z")

</div>


