# Storing Percolate Queries

**URL:** <https://discuss.elastic.co/t/storing-percolate-queries/28194>\
**Category:** Elasticsearch\
**Created:** [August 27, 2015, 3:44pm UTC](https://discuss.elastic.co/t/storing-percolate-queries/28194 "2015-08-27T15:44:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![raunak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raunak/32/4446_2.png) [@raunak](https://discuss.elastic.co/u/raunak)\
**Post date:** [August 27, 2015, 3:44pm UTC](https://discuss.elastic.co/t/storing-percolate-queries/28194/1 "2015-08-27T15:44:12Z")

</div>

I'm new to ES, so please bear with me while I explain what I'm trying to do.

I'm using ES version 1.5.2, and making use of the JAVA APIs via JEST wrapper. I would like to create some percolate queries and store them in the index.

I understand that there is special index called '\_percolator' where I should store these queries, however, I can't seem to be able to create this index myself. Trying to store queries directly throws index does not exist error (on Searchly). In addition, I saw a slidedeck ([https://speakerdeck.com/javanna/whats-new-in-percolator?#80](https://speakerdeck.com/javanna/whats-new-in-percolator?#80)) which seems to suggest to store the queries in an index called 'anyindex'

So, my questions are...

- Which index should the percolate queries be stored in (for ES 1.5.2)
- If its in the '\_percolate', does this index have to be created explicitly?
- Should percolate queries be stored in the Index the same way as a document is? See snippet below.

This is how I tried storing a query using JEST;

```
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(QueryBuilders.matchQuery("stock", "apple"));
saveDoc(searchSourceBuilder, "company-apple", "_percolator", "stocks");

public JestResult saveDoc(Object doc, String docId, String indexName, String type) {
    Index index = new Index.Builder(doc).id(docId).index(indexName).type(type).build();
    return client.execute(index);
}

```

Thanks for your input and suggestions.

Raunak

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [August 28, 2015, 8:32pm UTC](https://discuss.elastic.co/t/storing-percolate-queries/28194/2 "2015-08-28T20:32:46Z")

</div>

Percolator queries can be stored in any index, but you need to store the queries under a special type, called `.percolator`. Further more the query (for example the match query in your example) needs to be stored under the top level `query` son field. In your example you're storing an entire search request, which should work because the query part is serialized under the top level `query` field. The percolator ignores any other content.

---

<div class="post-metadata">

**Author:** ![raunak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raunak/32/4446_2.png) [@raunak](https://discuss.elastic.co/u/raunak)\
**Post date:** [September 1, 2015, 10:22am UTC](https://discuss.elastic.co/t/storing-percolate-queries/28194/3 "2015-09-01T10:22:38Z")

</div>

Thanks @mvg.

In addition to your suggestion, I needed to convert searchSourceBuilder object to String before saving it.

---

<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:52pm UTC](https://discuss.elastic.co/t/storing-percolate-queries/28194/4 "2017-07-05T23:52:55Z")

</div>


