# Best practice for storing my queries

**URL:** https://discuss.elastic.co/t/best-practice-for-storing-my-queries/42118
**Category:** Elasticsearch
**Created:** [February 18, 2016, 9:52am UTC](https://discuss.elastic.co/t/best-practice-for-storing-my-queries/42118 "2016-02-18T09:52:48Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![tpraizler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tpraizler/32/46271_2.png) [@tpraizler](https://discuss.elastic.co/u/tpraizler)
#### Post date: [February 18, 2016, 9:52am UTC](https://discuss.elastic.co/t/best-practice-for-storing-my-queries/42118/1 "2016-02-18T09:52:49Z")

</div>

I have a web application, in which users can define a little complex search queries.  
I want to be able to store those queries for them, so those queries will be available any time.

So If a user login to my system , he can get lets say 4 search queries which he can click and run.  
Those for queries are unique and should be available only for this user.

What is the best solution here? is there a good way to save those queries?

---

<div class="post-metadata">

### Author: ![ddorian43](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ddorian43/32/36093_2.png) [@ddorian43](https://discuss.elastic.co/u/ddorian43)
#### Post date: [February 18, 2016, 10:42am UTC](https://discuss.elastic.co/t/best-practice-for-storing-my-queries/42118/2 "2016-02-18T10:42:59Z")

</div>

What is the problem where ? Just use the whole query (or a hash of it)(make sure the "body" has ordered keys) as a unique-index (or id) and store it in a database/table or elasticsearch/index.  
Also store a "user\_id", "created\_on" on the document/row etc.

---

<div class="post-metadata">

### Author: ![tpraizler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tpraizler/32/46271_2.png) [@tpraizler](https://discuss.elastic.co/u/tpraizler)
#### Post date: [February 18, 2016, 11:14am UTC](https://discuss.elastic.co/t/best-practice-for-storing-my-queries/42118/3 "2016-02-18T11:14:12Z")

</div>

Thanks @ddorian43!

Using a relational database to save this information is definitly an option.  
I though maybe elasticsearch has its own way of doing this, like using the precolator for example.

Here is a [post](http://stackoverflow.com/questions/13050136/register-and-call-query-in-elasticsearch) talking exactly on this use case.  
There is a suggestion to use filter alias. The thing is that question is a little out dated, and I am not sure if it is recommended or not.

---

<div class="post-metadata">

### Author: ![ddorian43](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ddorian43/32/36093_2.png) [@ddorian43](https://discuss.elastic.co/u/ddorian43)
#### Post date: [February 18, 2016, 11:40am UTC](https://discuss.elastic.co/t/best-practice-for-storing-my-queries/42118/4 "2016-02-18T11:40:19Z")

</div>

I'm afraid you're overthinking. Just store it in rdbms/es/mongodb/redis/whatever.  
Filter aliases looks to not be best for your case.

---

<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 5, 2017, 11:15pm UTC](https://discuss.elastic.co/t/best-practice-for-storing-my-queries/42118/5 "2017-07-05T23:15:17Z")

</div>


