# Cannot handle query parameters in plugin

**URL:** <https://discuss.elastic.co/t/cannot-handle-query-parameters-in-plugin/73339>\
**Category:** Elasticsearch\
**Created:** [January 31, 2017, 10:24am UTC](https://discuss.elastic.co/t/cannot-handle-query-parameters-in-plugin/73339 "2017-01-31T10:24:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vglazkov](https://avatars.discourse-cdn.com/v4/letter/v/ecc23a/32.png) [@vglazkov](https://discuss.elastic.co/u/vglazkov)\
**Post date:** [January 31, 2017, 10:24am UTC](https://discuss.elastic.co/t/cannot-handle-query-parameters-in-plugin/73339/1 "2017-01-31T10:24:56Z")

</div>

Hi,

I'm trying to register custom query parameter in my plugin handler like this one:

```
public class EssenceRestAction extends BaseRestHandler {

    @Inject
    public EssenceRestAction(Settings settings, RestController controller) {
        super(settings);
        controller.registerHandler(GET, "/_hello", this);
        controller.registerHandler(GET, "/_hello/{name}", this);
    }

```

But when I send request to my custom REST endpoint in the test within this code:

```
Response response = client.performRequest("GET", "/_hello",
        Collections.singletonMap("name", ids.get(i)), entity);

```

I've got this:

```
org.elasticsearch.client.ResponseException: GET http://localhost:9200/_hello?name=005f3370-4626-4309-92a5-def32fae7e87: HTTP/1.1 400 Bad Request
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"request [/_hello] contains unrecognized parameter: [name]"}],"type":"illegal_argument_exception","reason":"request [/_hello] contains unrecognized parameter: [name]"},"status":400}

```

How can I correctly register my REST endpoint to handle query parameters? Note: I've also tried to register only controller.registerHandler(GET, "/\_hello/{name}", this); but got the same error.

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [January 31, 2017, 12:28pm UTC](https://discuss.elastic.co/t/cannot-handle-query-parameters-in-plugin/73339/2 "2017-01-31T12:28:27Z")

</div>

Hi,

just to make sure, which version are you on?

> [@vglazkov](#):
>
> {"error":{"root\_cause":[{"type":"illegal\_argument\_exception","reason":"request [/\_hello] contains unrecognized parameter: [name]"}],"type":"illegal\_argument\_exception","reason":"request [/\_hello] contains unrecognized parameter: [name]"},"status":400}

Judging from this error message, you don't read the "name" parameter when processing the incoming request. This is usually done via `RestRequest#param(parameterName)` somewhere in your implementation of `BaseRestHandler#prepareRequest()`.

---

<div class="post-metadata">

**Author:** ![vglazkov](https://avatars.discourse-cdn.com/v4/letter/v/ecc23a/32.png) [@vglazkov](https://discuss.elastic.co/u/vglazkov)\
**Post date:** [January 31, 2017, 2:16pm UTC](https://discuss.elastic.co/t/cannot-handle-query-parameters-in-plugin/73339/3 "2017-01-31T14:16:10Z")

</div>

Hi, Christoph!

Thanks for your answer. My Elasticsearch version is 5.1.2. I get what was wrong with my code. I was dealing with parameters inside lambda like this one:

```
@Override
protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient nodeClient) throws IOException {
  return channel -> {
    String id = restRequest.param("name");

```

which leads to the error that I've got above. However if you deal with parameters before lambda all should be fine.

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [January 31, 2017, 2:25pm UTC](https://discuss.elastic.co/t/cannot-handle-query-parameters-in-plugin/73339/4 "2017-01-31T14:25:58Z")

</div>

Glad this solved it 😉

---

<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:** [February 28, 2017, 2:26pm UTC](https://discuss.elastic.co/t/cannot-handle-query-parameters-in-plugin/73339/5 "2017-02-28T14:26:39Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
