Java api - unable to percolate


(db-2) #1

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?


(Shay Banon) #2

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
.

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


(system) #3