How to add Percolation at indexing time


(IronMike) #1

//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,
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/77f6147e-f370-457c-90ef-4c557e884bf5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #2