# Java api - unable to percolate

**URL:** <https://discuss.elastic.co/t/java-api-unable-to-percolate/5417>\
**Category:** Elasticsearch\
**Created:** [September 20, 2011, 6:21pm UTC](https://discuss.elastic.co/t/java-api-unable-to-percolate/5417 "2011-09-20T18:21:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![db\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/db_2/32/3130_2.png) [@db\_2](https://discuss.elastic.co/u/db_2)\
**Post date:** [September 20, 2011, 6:21pm UTC](https://discuss.elastic.co/t/java-api-unable-to-percolate/5417/1 "2011-09-20T18:21:28Z")

</div>

Hi to all, i'm new to ES ;  
I'm trying to using the percolate feature with the Java API;  
I copied the example in the guide but it doesn't work for me at all;

with version 1 of this code i have a Exception Caused by:  
org.elasticsearch.indices.IndexMissingException: [testindex] missing  
// on startup  
//  
Client client = new TransportClient()  
.addTransportAddress(new  
InetSocketTransportAddress("localhost", 9300))  
.addTransportAddress(new  
InetSocketTransportAddress("localhost", 9300));

```
try {
  client.prepareIndex("_percolator", "myDocumentType",

```

"myQueryName")  
.setSource(jsonBuilder()  
.startObject()  
.field("content", "amazing")  
.endObject())  
.setRefresh(true)  
.execute().actionGet();  
} catch (Exception e) {  
System.out.println(e.toString()); //To change body of catch  
statement use File | Settings | File Templates.  
}

//Build a document to check against the percolator  
XContentBuilder docBuilder = null;  
try {  
docBuilder = XContentFactory.jsonBuilder().startObject();  
docBuilder.field("content", "This is amazing!");  
docBuilder.endObject();  
} catch (IOException e) {  
e.printStackTrace(); //To change body of catch statement use  
File | Settings | File Templates.  
}

//Percolate  
PercolateResponse response =  
client.preparePercolate("testindex",  
"myDocumentType").setSource(docBuilder).execute().actionGet();

for(String result : response) {  
//Handle the result which is the name of  
//the query in the percolator  
}  
client.close();

So if i create a testindex with cURL, the program become idle on  
client.preparePercolate("testindex",  
"myDocumentType").setSource(docBuilder).execute().actionGet();  
and wait forever;

if i use "\_percolator" instead of "testindex" i get this following  
Exception  
Caused by: org.elasticsearch.index.percolator.PercolatorException:  
[\_percolator] No doc to percolate in the request

I think i'm missing something important.. can somebody help me please?

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [September 20, 2011, 11:25pm UTC](https://discuss.elastic.co/t/java-api-unable-to-percolate/5417/2 "2011-09-20T23:25:58Z")

</div>

Have a look at this code (some simple tests for percolator using the Java  
API) for sample of how to do percolation:  
[https://github.com/elasticsearch/elasticsearch/blob/master/modules/test/integration/src/test/java/org/elasticsearch/test/integration/percolator/SimplePercolatorTests.java](https://github.com/elasticsearch/elasticsearch/blob/master/modules/test/integration/src/test/java/org/elasticsearch/test/integration/percolator/SimplePercolatorTests.java)  
.

You have several problems in your code, though the fact that it gets stuck  
is strange..., I will try and recreate. In general though, you need to  
register a query against the \_percoaltor index, with the index name you wish  
that query to be registered against.

On Tue, Sep 20, 2011 at 9:21 PM, DB [damiano.braga@gmail.com](mailto:damiano.braga@gmail.com) wrote:

> Hi to all, i'm new to ES ;  
> I'm trying to using the percolate feature with the Java API;  
> I copied the example in the guide but it doesn't work for me at all;
> 
> with version 1 of this code i have a Exception Caused by:  
> org.elasticsearch.indices.IndexMissingException: [testindex] missing  
> // on startup  
> //  
> Client client = new TransportClient()  
> .addTransportAddress(new  
> InetSocketTransportAddress("localhost", 9300))  
> .addTransportAddress(new  
> InetSocketTransportAddress("localhost", 9300));
> 
> try {  
> client.prepareIndex("\_percolator", "myDocumentType",  
> "myQueryName")  
> .setSource(jsonBuilder()  
> .startObject()  
> .field("content", "amazing")  
> .endObject())  
> .setRefresh(true)  
> .execute().actionGet();  
> } catch (Exception e) {  
> System.out.println(e.toString()); //To change body of catch  
> statement use File | Settings | File Templates.  
> }
> 
> //Build a document to check against the percolator  
> XContentBuilder docBuilder = null;  
> try {  
> docBuilder = XContentFactory.jsonBuilder().startObject();  
> docBuilder.field("content", "This is amazing!");  
> docBuilder.endObject();  
> } catch (IOException e) {  
> e.printStackTrace(); //To change body of catch statement use  
> File | Settings | File Templates.  
> }
> 
> //Percolate  
> PercolateResponse response =  
> client.preparePercolate("testindex",  
> "myDocumentType").setSource(docBuilder).execute().actionGet();
> 
> for(String result : response) {  
> //Handle the result which is the name of  
> //the query in the percolator  
> }  
> client.close();
> 
> So if i create a testindex with cURL, the program become idle on  
> client.preparePercolate("testindex",  
> "myDocumentType").setSource(docBuilder).execute().actionGet();  
> and wait forever;
> 
> if i use "\_percolator" instead of "testindex" i get this following  
> Exception  
> Caused by: org.elasticsearch.index.percolator.PercolatorException:  
> [\_percolator] No doc to percolate in the request
> 
> I think i'm missing something important.. can somebody help me please?

---

<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, 3:53am UTC](https://discuss.elastic.co/t/java-api-unable-to-percolate/5417/3 "2017-07-06T03:53:58Z")

</div>


