# How to add Percolation at indexing time

**URL:** <https://discuss.elastic.co/t/how-to-add-percolation-at-indexing-time/19607>\
**Category:** Elasticsearch\
**Created:** [September 3, 2014, 9:18pm UTC](https://discuss.elastic.co/t/how-to-add-percolation-at-indexing-time/19607 "2014-09-03T21:18:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![IronMike](https://avatars.discourse-cdn.com/v4/letter/i/e9a140/32.png) [@IronMike](https://discuss.elastic.co/u/IronMike)\
**Post date:** [September 3, 2014, 9:18pm UTC](https://discuss.elastic.co/t/how-to-add-percolation-at-indexing-time/19607/1 "2014-09-03T21:18:06Z")

</div>

//createIndex ...

//Register Percolator

QueryBuilder qb = QueryBuilders.matchQuery("content", "taxes");  
client.prepareIndex(index, ".percolator", "harkinQuery")  
.setSource(jsonBuilder()  
.startObject()  
.field("query", qb) // Register the query  
.endObject())  
.setRefresh(true) // Needed when the query shall be available immediately  
.execute().actionGet();

//index with BulkProcessor  
for(i=0; i\< numDocs; i++)  
{  
JSONObject jDoc = getDoc[i];  
...

bulkProcessor.add(Requests.indexRequest(index).type(type).id(jDoc.  
getString("id")).source(jDoc.toString()));  
...  
}

Looking  
at [http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/percolate.html](http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/percolate.html),  
Percolate API is used like this, but I am not sure how I can use it in  
combination with bulk index request shown in my above code?

//Percolate  
PercolateResponse response = client.preparePercolate()  
.setIndices("myIndexName")  
.setDocumentType("myDocumentType")  
.setSource(docBuilder).execute().actionGet();  
//Iterate over the results  
for(PercolateResponse.Match match : response) {  
//Handle the result which is the name of  
//the query in the percolator  
}

--  
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/77f6147e-f370-457c-90ef-4c557e884bf5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/77f6147e-f370-457c-90ef-4c557e884bf5%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:04am UTC](https://discuss.elastic.co/t/how-to-add-percolation-at-indexing-time/19607/2 "2017-07-06T01:04:32Z")

</div>


