# Help with Java Clint and Alias

**URL:** https://discuss.elastic.co/t/help-with-java-clint-and-alias/39570
**Category:** Elasticsearch
**Created:** [January 19, 2016, 5:03pm UTC](https://discuss.elastic.co/t/help-with-java-clint-and-alias/39570 "2016-01-19T17:03:52Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Fabio\_Ebner](https://avatars.discourse-cdn.com/v4/letter/f/ccd318/32.png) [@Fabio\_Ebner](https://discuss.elastic.co/u/Fabio_Ebner)
#### Post date: [January 19, 2016, 5:03pm UTC](https://discuss.elastic.co/t/help-with-java-clint-and-alias/39570/1 "2016-01-19T17:03:52Z")

</div>

Today I use this code to execute one select

```
QueryBuilder query = QueryBuilders.matchQuery(where,what);
		QueryBuilder filter = QueryBuilders.filteredQuery(query, filterBuilder);
		client.admin().indices().prepareAliases().addAlias("binhoca",this.getIndex()).execute();
		SearchResponse response = client.prepareSearch(this.getIndex())
				.setTypes(this.getType())
				.setQuery(filter)
				.addSort(campoOrder, tipoSorter)
				.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
				.setSize(5000).execute()
				.actionGet();
		SearchHit[] hits = response.getHits().getHits();
		List<Map<String, Object>> retorno = new ArrayList<Map<String, Object>>();

```

So now I create one alias to my indice what I need to change to use alias instead indice name?

tks

---

<div class="post-metadata">

### Author: ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)
#### Post date: [January 19, 2016, 5:21pm UTC](https://discuss.elastic.co/t/help-with-java-clint-and-alias/39570/2 "2016-01-19T17:21:59Z")

</div>

You would simply use in your call to prepareSearch()

client.prepareSearch("binhoca")...

---

<div class="post-metadata">

### Author: ![Fabio\_Ebner](https://avatars.discourse-cdn.com/v4/letter/f/ccd318/32.png) [@Fabio\_Ebner](https://discuss.elastic.co/u/Fabio_Ebner)
#### Post date: [January 19, 2016, 5:39pm UTC](https://discuss.elastic.co/t/help-with-java-clint-and-alias/39570/3 "2016-01-19T17:39:06Z")

</div>

Sorry. the line  
`client.admin().indices().prepareAliases().addAlias("binhoca",this.getIndex()).execute();`  
are from tests but don`t work

I already try to only change the  
`SearchResponse response = client.prepareSearch(this.getIndex())`

to

```
SearchResponse response = client.prepareSearch("binhoca").
.setTypes(this.getType())
				.setQuery(filter)
				.addSort(campoOrder, tipoSorter)
				.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
				.setSize(5000).execute()
				.actionGet();

```

and don`t work.. if I go to browser and call [http://localhost:9200/binhoca/\_search?pretty](http://localhost:9200/binhoca/_search?pretty) works fine.. but not with client

---

<div class="post-metadata">

### Author: ![Fabio\_Ebner](https://avatars.discourse-cdn.com/v4/letter/f/ccd318/32.png) [@Fabio\_Ebner](https://discuss.elastic.co/u/Fabio_Ebner)
#### Post date: [January 19, 2016, 5:41pm UTC](https://discuss.elastic.co/t/help-with-java-clint-and-alias/39570/4 "2016-01-19T17:41:35Z")

</div>

Sorry man.. my Bad..

I forgot to change the type 😃 now works..

tks

---

<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 5, 2017, 11:23pm UTC](https://discuss.elastic.co/t/help-with-java-clint-and-alias/39570/5 "2017-07-05T23:23:21Z")

</div>


