# How to use 'run as' in the Java transport client

**URL:** https://discuss.elastic.co/t/how-to-use-run-as-in-the-java-transport-client/104566
**Category:** Elasticsearch
**Created:** [October 19, 2017, 1:49pm UTC](https://discuss.elastic.co/t/how-to-use-run-as-in-the-java-transport-client/104566 "2017-10-19T13:49:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![adesouza](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@adesouza](https://discuss.elastic.co/u/adesouza)
#### Post date: [October 19, 2017, 1:49pm UTC](https://discuss.elastic.co/t/how-to-use-run-as-in-the-java-transport-client/104566/1 "2017-10-19T13:49:46Z")

</div>

Hi,

I'm using the 5.5.0 Java transport client and I'd like to submit a search request using the 'run as' feature, but I'm not sure how I go about it. Are there any examples available?

Thanks,

Aaron

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [October 24, 2017, 10:18am UTC](https://discuss.elastic.co/t/how-to-use-run-as-in-the-java-transport-client/104566/2 "2017-10-24T10:18:15Z")

</div>

Do something like this

```auto
Map<String, String> headers = new HashMap<>();
headers.put("Authorization", UsernamePasswordToken.basicAuthHeaderValue("your_user", new SecureString("password".toCharArray())));
headers.put("es-security-runas-user", "your_user_to_run_as");

client.filterWithHeader(headers).admin().cluster().prepareHealth().get();

```

---

<div class="post-metadata">

### Author: ![adesouza](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@adesouza](https://discuss.elastic.co/u/adesouza)
#### Post date: [October 25, 2017, 12:37pm UTC](https://discuss.elastic.co/t/how-to-use-run-as-in-the-java-transport-client/104566/3 "2017-10-25T12:37:13Z")

</div>

Thanks @spinscale I'll give it a try when I get the chance.

---

<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: [November 22, 2017, 12:37pm UTC](https://discuss.elastic.co/t/how-to-use-run-as-in-the-java-transport-client/104566/4 "2017-11-22T12:37:31Z")

</div>

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