Storing Percolate Queries


(Raunak) #1

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) 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


(Martijn Van Groningen) #2

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.


(Raunak) #3

Thanks @mvg.

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


(system) #4