Skip to content

Commit

Permalink
percolate REST API should support source parameter
Browse files Browse the repository at this point in the history
As stated in documentation, we should support `?source=` parameter in percolate REST operations.

This is how to reproduce it:

```sh
curl -XDELETE "http://localhost:9200/test"

curl -XPUT "http://localhost:9200/test/.percolator/1" -d'
{
"query" : {
"match" : {
"foo" : "bar"
}
}
}'

# This one works
curl -XPOST "http://localhost:9200/test/message/_percolate" -d '{
"doc" : {
"foo" : "bar is in foo"
}
}'

# This one gives: BroadcastShardOperationFailedException[[test][2] ]; nested: PercolateException[failed to percolate]; nested: ElasticsearchIllegalArgumentException[Nothing to percolate];
curl -XGET "http://localhost:9200/test/message/_percolate?source=%7B%22doc%22%3A%7B%22foo%22%3A%22bar%20is%20in%20foo%22%7D%7D"
```

Closes #4903.
  • Loading branch information
dadoonet committed Jan 28, 2014
1 parent 1d6f822 commit 58b7e79
Showing 1 changed file with 14 additions and 1 deletion.
Expand Up @@ -23,6 +23,8 @@
import org.elasticsearch.action.percolate.PercolateRequest;
import org.elasticsearch.action.percolate.PercolateResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
Expand Down Expand Up @@ -52,7 +54,18 @@ public RestPercolateAction(Settings settings, Client client, RestController cont
public void handleRequest(final RestRequest request, final RestChannel channel) {
PercolateRequest percolateRequest = new PercolateRequest(request.param("index"), request.param("type"));
percolateRequest.listenerThreaded(false);
percolateRequest.source(request.content(), request.contentUnsafe());

BytesReference content = null;
if (request.hasContent()) {
content = request.content();
} else {
String source = request.param("source");
if (source != null) {
content = new BytesArray(source);
}
}

percolateRequest.source(content, request.contentUnsafe());

// we just send a response, no need to fork
percolateRequest.listenerThreaded(false);
Expand Down

0 comments on commit 58b7e79

Please sign in to comment.