# How to retrieve elasticsearch Data from Java application

**URL:** <https://discuss.elastic.co/t/how-to-retrieve-elasticsearch-data-from-java-application/10148>\
**Category:** Elasticsearch\
**Created:** [December 21, 2012, 8:52am UTC](https://discuss.elastic.co/t/how-to-retrieve-elasticsearch-data-from-java-application/10148 "2012-12-21T08:52:14Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Janusz\_Dalecki](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Janusz\_Dalecki](https://discuss.elastic.co/u/Janusz_Dalecki)\
**Post date:** [December 21, 2012, 8:52am UTC](https://discuss.elastic.co/t/how-to-retrieve-elasticsearch-data-from-java-application/10148/1 "2012-12-21T08:52:14Z")

</div>

Hi Everybody,  
I am trying to use elasticsearch from Java. (I am running elasticsearch server locally on my laptop using java 6 in Windows 7 64 bits and the client under eclipse Indigo)  
First of all I have followed the tutorial “ElasticSearch in 5 minutes” and I created a few indexed data as per tutorial. (e.i. [http://localhost:9200/blog/post/1](http://localhost:9200/blog/post/1) (in particular “Dilbert Brown” item - using postman [http://localhost:9200/blog/user/dilbert](http://localhost:9200/blog/user/dilbert)' '{ "name" : "Dilbert Brown" }').

I have checked that the record and it does exist – using again postman util.  
Everything works fine from dos command prompt – as described by the tutorial  
My question is: how do I retrieve it from elasticsearch using Java. I have tried this code?  
Client client = new TransportClient().addTransportAddress(new InetSocketTransportAddress("localhost", 9200));  
SearchResponse response = client.prepareSearch("mongoindex").setSearchType(  
SearchType.DFS\_QUERY\_THEN\_FETCH).setQuery(QueryBuilders.termQuery("name", "Dilbert Brown"))  
.setFrom(0).setSize(60).setExplain(true).execute().actionGet();

```
  SearchHit[] docs = response.getHits().getHits();

```

From prepareSearch method I am getting:

org.elasticsearch.client.transport.NoNodeAvailableException: No node available  
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:205)  
at org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:97)  
at org.elasticsearch.client.support.AbstractClient.search(AbstractClient.java:206)  
at org.elasticsearch.client.transport.TransportClient.search(TransportClient.java:365)  
at org.elasticsearch.action.search.SearchRequestBuilder.doExecute(SearchRequestBuilder.java:743)  
at org.elasticsearch.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:53)  
at org.elasticsearch.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:47)  
at com.tycoint.eams.servlet.InitContextListener.contextInitialized(InitContextListener.java:94)  
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)  
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)  
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)  
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)  
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)  
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)  
at java.util.concurrent.FutureTask.run(FutureTask.java:138)  
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  
at java.lang.Thread.run(Thread.java:662)

What Am I doing wrong?  
Regards,  
Janusz

---

<div class="post-metadata">

**Author:** ![Rafal\_Kuc\_3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafal_kuc_3/32/799_2.png) [@Rafal\_Kuc\_3](https://discuss.elastic.co/u/Rafal_Kuc_3)\
**Post date:** [December 21, 2012, 9:16am UTC](https://discuss.elastic.co/t/how-to-retrieve-elasticsearch-data-from-java-application/10148/2 "2012-12-21T09:16:39Z")

</div>

Hello!

The exception indicates that your client can't connect to the  
Elasticsearch cluster. I see you are using 9200 port, try 9300 - it is  
the port for communication using transport client.

--  
Regards,  
Rafał Kuć  
Sematext :: [http://sematext.com/](http://sematext.com/) :: Solr - Lucene - Nutch - Elasticsearch

> Hi Everybody,  
> I am trying to use elasticsearch from Java. (I am running elasticsearch  
> server locally on my laptop using java 6 in Windows 7 64 bits and the client  
> under eclipse Indigo)  
> First of all I have followed the tutorial "Elasticsearch in 5 minutes" and I  
> created a few indexed data as per tutorial. (e.i.  
> [http://localhost:9200/blog/post/1](http://localhost:9200/blog/post/1) (in particular "Dilbert Brown" item -  
> using postman [http://localhost:9200/blog/user/dilbert](http://localhost:9200/blog/user/dilbert)' '{ "name" : "Dilbert  
> Brown" }').

> I have checked that the record and it does exist - using again postman util.  
> Everything works fine from dos command prompt - as described by the tutorial  
> My question is: how do I retrieve it from elasticsearch using Java. I have  
> tried this code?  
> Client client = new TransportClient().addTransportAddress(new  
> InetSocketTransportAddress("localhost", 9200));  
> SearchResponse response =  
> client.prepareSearch("mongoindex").setSearchType(
> 
> SearchType.DFS\_QUERY\_THEN\_FETCH).setQuery(QueryBuilders.termQuery("name",  
> "Dilbert Brown"))
> 
> .setFrom(0).setSize(60).setExplain(true).execute().actionGet();

> ```
> SearchHit[] docs = response.getHits().getHits();
> 
> ```

> From prepareSearch method I am getting:

> org.elasticsearch.client.transport.NoNodeAvailableException: No node  
> available  
> at  
> org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:205)  
> at  
> org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:97)  
> at  
> org.elasticsearch.client.support.AbstractClient.search(AbstractClient.java:206)  
> at  
> org.elasticsearch.client.transport.TransportClient.search(TransportClient.java:365)  
> at  
> org.elasticsearch.action.search.SearchRequestBuilder.doExecute(SearchRequestBuilder.java:743)  
> at  
> org.elasticsearch.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:53)  
> at  
> org.elasticsearch.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:47)  
> at  
> com.tycoint.eams.servlet.InitContextListener.contextInitialized(InitContextListener.java:94)  
> at  
> org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)  
> at  
> org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)  
> at  
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)  
> at  
> org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)  
> at  
> org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)  
> at  
> java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)  
> at java.util.concurrent.FutureTask.run(FutureTask.java:138)  
> at  
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  
> at  
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  
> at java.lang.Thread.run(Thread.java:662)

> What Am I doing wrong?  
> Regards,  
> Janusz

> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/How-to-retrieve-elasticsearch-Data-from-Java-application-tp4027312.html](http://elasticsearch-users.115913.n3.nabble.com/How-to-retrieve-elasticsearch-Data-from-Java-application-tp4027312.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--

---

<div class="post-metadata">

**Author:** ![Janusz\_Dalecki](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Janusz\_Dalecki](https://discuss.elastic.co/u/Janusz_Dalecki)\
**Post date:** [December 21, 2012, 9:55am UTC](https://discuss.elastic.co/t/how-to-retrieve-elasticsearch-data-from-java-application/10148/3 "2012-12-21T09:55:08Z")

</div>

Same thing. It actually works from Explore on port 9200 - that is way I was using 9200 in a first place.  
Regards,  
Janusz

---

<div class="post-metadata">

**Author:** ![Rafal\_Kuc\_3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafal_kuc_3/32/799_2.png) [@Rafal\_Kuc\_3](https://discuss.elastic.co/u/Rafal_Kuc_3)\
**Post date:** [December 21, 2012, 10:06am UTC](https://discuss.elastic.co/t/how-to-retrieve-elasticsearch-data-from-java-application/10148/4 "2012-12-21T10:06:34Z")

</div>

Hello!

The 9200 is used to communicate using HTTP API, the 9300 is used for  
the communication using TransportClient which you are using in your  
Java code.

I don't know if you've change the cluster name, but try something like  
this:

TransportClient client = new TransportClient(ImmutableSettings.settingsBuilder().put("cluster.name", clusterName).build());  
client.addTransportAddress(new InetSocketTransportAddress("localhost", 9300));

I also noticed you have the following code:

client.prepareSearch("mongoindex")

Do you have 'mongoindex' index created ?

--  
Regards,  
Rafał Kuć  
Sematext :: [http://sematext.com/](http://sematext.com/) :: Solr - Lucene - Nutch - Elasticsearch

> Same thing. It actually works from Explore on port 9200 - that is way I was  
> using 9200 in a first place.  
> Regards,  
> Janusz

> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/How-to-retrieve-elasticsearch-Data-from-Java-application-tp4027312p4027315.html](http://elasticsearch-users.115913.n3.nabble.com/How-to-retrieve-elasticsearch-Data-from-Java-application-tp4027312p4027315.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--

---

<div class="post-metadata">

**Author:** ![Janusz\_Dalecki](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Janusz\_Dalecki](https://discuss.elastic.co/u/Janusz_Dalecki)\
**Post date:** [December 22, 2012, 2:04am UTC](https://discuss.elastic.co/t/how-to-retrieve-elasticsearch-data-from-java-application/10148/5 "2012-12-22T02:04:45Z")

</div>

Hi,  
Thanks a lot Rafał for answering my question. I have just been asked to  
evaluate some different nosql products for our work – in this field I am  
the beginner – so thanks for your help. I am basically following the  
tutorial to learn more about elasticsearch (“Elasticsearch in 5 minutes“ -  
[http://www.elasticsearchtutorial.com/elasticsearch-in-5-minutes.html](http://www.elasticsearchtutorial.com/elasticsearch-in-5-minutes.html)). You  
were right I did not specify proper index. If I follow the tutorial I  
thought the index is “blog”, isn’t it? But when I specify index “blog” I  
don’t get any results:

String clusterName = "elasticsearch";

```
  TransportClient client = *new* TransportClient(ImmutableSettings.*

```

settingsBuilder\*().put(

```
      "cluster.name", clusterName).build());

  client.addTransportAddress(*new* InetSocketTransportAddress(

```

"localhost", 9300));

```
  SearchResponse response = client.prepareSearch("blog").setSearchType(

      SearchType.*DFS_QUERY_THEN_FETCH*).setQuery(

      QueryBuilders.*termQuery*("name", "Dilbert Brown"

```

)).setFrom(0).setSize(60).setExplain(_true_)

```
      .execute().actionGet();

  SearchHit[] docs = response.getHits().getHits();

  System.*out*.println("size is " + docs.length);
  client.close(); The size is 0. Obviously I do not understand 

```

something. What am I doing wrong?  
Regards,  
Janusz

On Friday, December 21, 2012 9:06:34 PM UTC+11, Rafał Kuć wrote:

> Hello!
> 
> The 9200 is used to communicate using HTTP API, the 9300 is used for  
> the communication using TransportClient which you are using in your  
> Java code.
> 
> I don't know if you've change the cluster name, but try something like  
> this:
> 
> TransportClient client = new  
> TransportClient(ImmutableSettings.settingsBuilder().put("cluster.name",  
> clusterName).build());  
> client.addTransportAddress(new InetSocketTransportAddress("localhost",  
> 9300));
> 
> I also noticed you have the following code:
> 
> client.prepareSearch("mongoindex")
> 
> Do you have 'mongoindex' index created ?
> 
> --  
> Regards,  
> Rafał Kuć  
> Sematext :: [http://sematext.com/](http://sematext.com/) :: Solr - Lucene - Nutch -  
> Elasticsearch
> 
> > Same thing. It actually works from Explore on port 9200 - that is way I  
> > was  
> > using 9200 in a first place.  
> > Regards,  
> > Janusz
> 
> > --  
> > View this message in context:
> 
> [http://elasticsearch-users.115913.n3.nabble.com/How-to-retrieve-elasticsearch-Data-from-Java-application-tp4027312p4027315.html](http://elasticsearch-users.115913.n3.nabble.com/How-to-retrieve-elasticsearch-Data-from-Java-application-tp4027312p4027315.html)
> 
> > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--

---

<div class="post-metadata">

**Author:** ![Janusz\_Dalecki](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Janusz\_Dalecki](https://discuss.elastic.co/u/Janusz_Dalecki)\
**Post date:** [December 22, 2012, 2:11am UTC](https://discuss.elastic.co/t/how-to-retrieve-elasticsearch-data-from-java-application/10148/6 "2012-12-22T02:11:28Z")

</div>

Hi,

Sorry for my previous post - not readable at all.

Thanks a lot Rafal for answering my question. I have just been asked to  
evaluate some different nosql products for our work – in this field I am  
the beginner – so thanks for your help.

I am basically following the tutorial to learn more about elasticsearch  
(“Elasticsearch in 5 minutes“ -  
[http://www.elasticsearchtutorial.com/elasticsearch-in-5-minutes.html](http://www.elasticsearchtutorial.com/elasticsearch-in-5-minutes.html)). You  
were right I did not specify proper index. If I follow the tutorial I  
thought the index is “blog”, isn’t it?

But when I specify index “blog” I don’t get any results:

String clusterName = "elasticsearch";

```
  TransportClient client = new 

```

TransportClient(ImmutableSettings.settingsBuilder().put(

```
      "cluster.name", clusterName).build());

  client.addTransportAddress(new 

```

InetSocketTransportAddress("localhost", 9300));

```
  SearchResponse response = client.prepareSearch("blog").setSearchType(

      SearchType.DFS_QUERY_THEN_FETCH).setQuery(

      QueryBuilders.termQuery("name", "Dilbert 

```

Brown")).setFrom(0).setSize(60).setExplain(true)

```
      .execute().actionGet();

  SearchHit[] docs = response.getHits().getHits();

  System.out.println("size is " + docs.length);

  client.close();

```

The size is 0. Obviously I do not understand something. What am I doing  
wrong?

Regards,

Janusz  
On Friday, December 21, 2012 7:52:14 PM UTC+11, JD wrote:

> Hi Everybody,  
> I am trying to use elasticsearch from Java. (I am running elasticsearch  
> server locally on my laptop using java 6 in Windows 7 64 bits and the  
> client  
> under eclipse Indigo)  
> First of all I have followed the tutorial “Elasticsearch in 5 minutes” and  
> I  
> created a few indexed data as per tutorial. (e.i.  
> [http://localhost:9200/blog/post/1](http://localhost:9200/blog/post/1) (in particular “Dilbert Brown” item -  
> using postman [http://localhost:9200/blog/user/dilbert](http://localhost:9200/blog/user/dilbert)' '{ "name" :  
> "Dilbert  
> Brown" }').
> 
> I have checked that the record and it does exist – using again postman  
> util.  
> Everything works fine from dos command prompt – as described by the  
> tutorial  
> My question is: how do I retrieve it from elasticsearch using Java. I have  
> tried this code?  
> Client client = new TransportClient().addTransportAddress(new  
> InetSocketTransportAddress("localhost", 9200));  
> SearchResponse response =  
> client.prepareSearch("mongoindex").setSearchType(
> 
> SearchType.DFS\_QUERY\_THEN\_FETCH).setQuery(QueryBuilders.termQuery("name",  
> "Dilbert Brown"))  
> .setFrom(0).setSize(60).setExplain(true).execute().actionGet();
> 
> ```
> SearchHit[] docs = response.getHits().getHits(); 
> 
> ```
> 
> From prepareSearch method I am getting:
> 
> org.elasticsearch.client.transport.NoNodeAvailableException: No node  
> available  
> at  
> org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:205)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:97)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.client.support.AbstractClient.search(AbstractClient.java:206)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.client.transport.TransportClient.search(TransportClient.java:365)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.action.search.SearchRequestBuilder.doExecute(SearchRequestBuilder.java:743)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:53)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:47)
> 
> ```
> at 
> 
> ```
> 
> com.tycoint.eams.servlet.InitContextListener.contextInitialized(InitContextListener.java:94)
> 
> ```
> at 
> 
> ```
> 
> org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
> 
> ```
> at 
> 
> ```
> 
> org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
> 
> ```
> at 
> 
> ```
> 
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)  
> at  
> org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
> 
> ```
> at 
> 
> ```
> 
> org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
> 
> ```
> at 
> 
> ```
> 
> java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)  
> at java.util.concurrent.FutureTask.run(FutureTask.java:138)  
> at  
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
> 
> ```
> at 
> 
> ```
> 
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
> 
> ```
> at java.lang.Thread.run(Thread.java:662) 
> 
> ```
> 
> What Am I doing wrong?  
> Regards,  
> Janusz
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/How-to-retrieve-elasticsearch-Data-from-Java-application-tp4027312.html](http://elasticsearch-users.115913.n3.nabble.com/How-to-retrieve-elasticsearch-Data-from-Java-application-tp4027312.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--

---

<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:** [December 22, 2012, 5:56am UTC](https://discuss.elastic.co/t/how-to-retrieve-elasticsearch-data-from-java-application/10148/7 "2012-12-22T05:56:53Z")

</div>

A term query is not analyzed, while the name field is. Analyzing a field  
means processing the value through the Lucene token filters and tokenizers.

Try using a match query or query string. Those queries will analyze the  
search string.

* * *

Ivan

On Fri, Dec 21, 2012 at 6:11 PM, JD [jdalecki@tycoint.com](mailto:jdalecki@tycoint.com) wrote:

> Dilbert

--

---

<div class="post-metadata">

**Author:** ![Janusz\_Dalecki](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Janusz\_Dalecki](https://discuss.elastic.co/u/Janusz_Dalecki)\
**Post date:** [December 22, 2012, 12:49pm UTC](https://discuss.elastic.co/t/how-to-retrieve-elasticsearch-data-from-java-application/10148/8 "2012-12-22T12:49:29Z")

</div>

Thanks Ivan,  
Can you refer me to some documentation about this please?  
Regards,  
Janusz

On Friday, December 21, 2012 7:52:14 PM UTC+11, JD wrote:

> Hi Everybody,  
> I am trying to use elasticsearch from Java. (I am running elasticsearch  
> server locally on my laptop using java 6 in Windows 7 64 bits and the  
> client  
> under eclipse Indigo)  
> First of all I have followed the tutorial “Elasticsearch in 5 minutes” and  
> I  
> created a few indexed data as per tutorial. (e.i.  
> [http://localhost:9200/blog/post/1](http://localhost:9200/blog/post/1) (in particular “Dilbert Brown” item -  
> using postman [http://localhost:9200/blog/user/dilbert](http://localhost:9200/blog/user/dilbert)' '{ "name" :  
> "Dilbert  
> Brown" }').
> 
> I have checked that the record and it does exist – using again postman  
> util.  
> Everything works fine from dos command prompt – as described by the  
> tutorial  
> My question is: how do I retrieve it from elasticsearch using Java. I have  
> tried this code?  
> Client client = new TransportClient().addTransportAddress(new  
> InetSocketTransportAddress("localhost", 9200));  
> SearchResponse response =  
> client.prepareSearch("mongoindex").setSearchType(
> 
> SearchType.DFS\_QUERY\_THEN\_FETCH).setQuery(QueryBuilders.termQuery("name",  
> "Dilbert Brown"))  
> .setFrom(0).setSize(60).setExplain(true).execute().actionGet();
> 
> ```
> SearchHit[] docs = response.getHits().getHits(); 
> 
> ```
> 
> From prepareSearch method I am getting:
> 
> org.elasticsearch.client.transport.NoNodeAvailableException: No node  
> available  
> at  
> org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:205)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:97)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.client.support.AbstractClient.search(AbstractClient.java:206)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.client.transport.TransportClient.search(TransportClient.java:365)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.action.search.SearchRequestBuilder.doExecute(SearchRequestBuilder.java:743)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:53)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:47)
> 
> ```
> at 
> 
> ```
> 
> com.tycoint.eams.servlet.InitContextListener.contextInitialized(InitContextListener.java:94)
> 
> ```
> at 
> 
> ```
> 
> org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
> 
> ```
> at 
> 
> ```
> 
> org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
> 
> ```
> at 
> 
> ```
> 
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)  
> at  
> org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
> 
> ```
> at 
> 
> ```
> 
> org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
> 
> ```
> at 
> 
> ```
> 
> java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)  
> at java.util.concurrent.FutureTask.run(FutureTask.java:138)  
> at  
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
> 
> ```
> at 
> 
> ```
> 
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
> 
> ```
> at java.lang.Thread.run(Thread.java:662) 
> 
> ```
> 
> What Am I doing wrong?  
> Regards,  
> Janusz
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/How-to-retrieve-elasticsearch-Data-from-Java-application-tp4027312.html](http://elasticsearch-users.115913.n3.nabble.com/How-to-retrieve-elasticsearch-Data-from-Java-application-tp4027312.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--

---

<div class="post-metadata">

**Author:** ![Rafal\_Kuc\_3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafal_kuc_3/32/799_2.png) [@Rafal\_Kuc\_3](https://discuss.elastic.co/u/Rafal_Kuc_3)\
**Post date:** [December 22, 2012, 12:56pm UTC](https://discuss.elastic.co/t/how-to-retrieve-elasticsearch-data-from-java-application/10148/9 "2012-12-22T12:56:32Z")

</div>

Hello!

Try looking at the query DSL and a query type you are interested in - [http://www.elasticsearch.org/guide/reference/query-dsl/](http://www.elasticsearch.org/guide/reference/query-dsl/)

If you want your query to be analyzed try using match query [http://www.elasticsearch.org/guide/reference/query-dsl/match-query.html](http://www.elasticsearch.org/guide/reference/query-dsl/match-query.html)

_--_

Regards,

Rafał Kuć

Sematext :: [http://sematext.com/](http://sematext.com/) _:: Solr - Lucene - Nutch - ElasticSearch_

Thanks Ivan,

Can you refer me to some documentation about this please?

Regards,

Janusz

On Friday, December 21, 2012 7:52:14 PM UTC+11, JD wrote:

Hi Everybody,

I am trying to use elasticsearch from Java. (I am running elasticsearch

server locally on my laptop using java 6 in Windows 7 64 bits and the client

under eclipse Indigo)

First of all I have followed the tutorial “ElasticSearch in 5 minutes” and I

created a few indexed data as per tutorial. (e.i.

[http://localhost:9200/blog/](http://localhost:9200/blog/post/1)[post/1](http://localhost:9200/blog/post/1) (in particular “Dilbert Brown” item -

using postman [http://localhost:9200/blog/](http://localhost:9200/blog/user/dilbert)[user/dilbert](http://localhost:9200/blog/user/dilbert)' '{ "name" : "Dilbert

Brown" }').

I have checked that the record and it does exist – using again postman util.

Everything works fine from dos command prompt – as described by the tutorial

My question is: how do I retrieve it from elasticsearch using Java. I have

tried this code?

```
 Client client = new TransportClient().addTransportAddress(new 

```

InetSocketTransportAddress("localhost", 9200));

```
  SearchResponse response = 

```

client.prepareSearch("mongoindex").setSearchType(

SearchType.DFS\_QUERY\_THEN\_FETCH).setQuery(QueryBuilders.termQuery("name",

"Dilbert Brown"))

```
      .setFrom(0).setSize(60).setExplain(true).execute().actionGet(); 

  SearchHit[] docs = response.getHits().getHits(); 

```

From prepareSearch method I am getting:

org.elasticsearch.client.transport.NoNodeAvailableException: No node

available

```
    at 

```

org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:205)

```
    at 

```

org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:97)

```
    at 

```

org.elasticsearch.client.support.AbstractClient.search(AbstractClient.java:206)

```
    at 

```

org.elasticsearch.client.transport.TransportClient.search(TransportClient.java:365)

```
    at 

```

org.elasticsearch.action.search.SearchRequestBuilder.doExecute(SearchRequestBuilder.java:743)

```
    at 

```

org.elasticsearch.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:53)

```
    at 

```

org.elasticsearch.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:47)

```
    at 

```

com.tycoint.eams.servlet.InitContextListener.contextInitialized(InitContextListener.java:94)

```
    at 

```

org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)

```
    at 

```

org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)

```
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 

    at 

```

org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)

```
    at 

```

org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)

```
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) 

    at java.util.concurrent.FutureTask.run(FutureTask.java:138) 

    at 

```

java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

```
    at 

```

java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

```
    at java.lang.Thread.run(Thread.java:662) 

```

What Am I doing wrong?

Regards,

Janusz

--

View this message in context: [http://elasticsearch-users.](http://elasticsearch-users.115913.n3.nabble.com/How-to-retrieve-elasticsearch-Data-from-Java-application-tp4027312.html)[115913.n3.nabble.com/How-to-](http://elasticsearch-users.115913.n3.nabble.com/How-to-retrieve-elasticsearch-Data-from-Java-application-tp4027312.html)[retrieve-elasticsearch-Data-](http://elasticsearch-users.115913.n3.nabble.com/How-to-retrieve-elasticsearch-Data-from-Java-application-tp4027312.html)[from-Java-application-](http://elasticsearch-users.115913.n3.nabble.com/How-to-retrieve-elasticsearch-Data-from-Java-application-tp4027312.html)[tp4027312.html](http://elasticsearch-users.115913.n3.nabble.com/How-to-retrieve-elasticsearch-Data-from-Java-application-tp4027312.html)

Sent from the ElasticSearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--

---

<div class="post-metadata">

**Author:** ![Janusz\_Dalecki](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Janusz\_Dalecki](https://discuss.elastic.co/u/Janusz_Dalecki)\
**Post date:** [December 23, 2012, 6:54am UTC](https://discuss.elastic.co/t/how-to-retrieve-elasticsearch-data-from-java-application/10148/10 "2012-12-23T06:54:00Z")

</div>

Hi Rafał,

Getting back to the "Elasticsearch in 5 minutes" -  
[http://www.elasticsearchtutorial.com/elasticsearch-in-5-minutes.html](http://www.elasticsearchtutorial.com/elasticsearch-in-5-minutes.html).

When they execute:

curl -XPUT '[http://localhost:9200/blog/post/1](http://localhost:9200/blog/post/1)' -d '  
{  
"user": "dilbert",  
"postDate": "2011-12-15",  
"body": "Search is hard. Search should be easy." ,  
"title": "On search"  
}

It creates in the Elasticsearch db a record:

{

```
"_index": "blog",

"_type": "post",

"_id": "1",

"_version": 1,

"exists": true,

"_source": {

    "user": "dilbert",

    "postDate": "2011-12-15",

    "body": "Search is hard. Search should be easy.",

    "title": "On search"

}

```

}

I can't understand why the "blog" word from path becomes a "\_index", the  
"post" word becomes a "\_type" and the "1" becomes a "\_id". Is this  
explained anywhere. I am not asking you to explain it all to me, but would  
appreciate if you could refer me to a good tutorial that explains how the  
url path components map to the record fields in the elasticsearch db. Also  
Java examples would be great to look at.

Regards,

Janusz

On Friday, December 21, 2012 7:52:14 PM UTC+11, JD wrote:

> Hi Everybody,  
> I am trying to use elasticsearch from Java. (I am running elasticsearch  
> server locally on my laptop using java 6 in Windows 7 64 bits and the  
> client  
> under eclipse Indigo)  
> First of all I have followed the tutorial "Elasticsearch in 5 minutes" and  
> I  
> created a few indexed data as per tutorial. (e.i.  
> [http://localhost:9200/blog/post/1](http://localhost:9200/blog/post/1) (in particular "Dilbert Brown" item -  
> using postman [http://localhost:9200/blog/user/dilbert](http://localhost:9200/blog/user/dilbert)' '{ "name" :  
> "Dilbert  
> Brown" }').
> 
> I have checked that the record and it does exist - using again postman  
> util.  
> Everything works fine from dos command prompt - as described by the  
> tutorial  
> My question is: how do I retrieve it from elasticsearch using Java. I have  
> tried this code?  
> Client client = new TransportClient().addTransportAddress(new  
> InetSocketTransportAddress("localhost", 9200));  
> SearchResponse response =  
> client.prepareSearch("mongoindex").setSearchType(
> 
> SearchType.DFS\_QUERY\_THEN\_FETCH).setQuery(QueryBuilders.termQuery("name",  
> "Dilbert Brown"))  
> .setFrom(0).setSize(60).setExplain(true).execute().actionGet();
> 
> ```
> SearchHit[] docs = response.getHits().getHits(); 
> 
> ```
> 
> From prepareSearch method I am getting:
> 
> org.elasticsearch.client.transport.NoNodeAvailableException: No node  
> available  
> at  
> org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:205)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:97)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.client.support.AbstractClient.search(AbstractClient.java:206)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.client.transport.TransportClient.search(TransportClient.java:365)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.action.search.SearchRequestBuilder.doExecute(SearchRequestBuilder.java:743)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:53)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:47)
> 
> ```
> at 
> 
> ```
> 
> com.tycoint.eams.servlet.InitContextListener.contextInitialized(InitContextListener.java:94)
> 
> ```
> at 
> 
> ```
> 
> org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
> 
> ```
> at 
> 
> ```
> 
> org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
> 
> ```
> at 
> 
> ```
> 
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)  
> at  
> org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
> 
> ```
> at 
> 
> ```
> 
> org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
> 
> ```
> at 
> 
> ```
> 
> java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)  
> at java.util.concurrent.FutureTask.run(FutureTask.java:138)  
> at  
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
> 
> ```
> at 
> 
> ```
> 
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
> 
> ```
> at java.lang.Thread.run(Thread.java:662) 
> 
> ```
> 
> What Am I doing wrong?  
> Regards,  
> Janusz
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/How-to-retrieve-elasticsearch-Data-from-Java-application-tp4027312.html](http://elasticsearch-users.115913.n3.nabble.com/How-to-retrieve-elasticsearch-Data-from-Java-application-tp4027312.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 23, 2012, 7:11am UTC](https://discuss.elastic.co/t/how-to-retrieve-elasticsearch-data-from-java-application/10148/11 "2012-12-23T07:11:21Z")

</div>

Have a look at my devoxx France (english translated) slides : [Elasticsearch - Devoxx France 2012 - English version | PPT](http://www.slideshare.net/dadoonet/elasticsearch-devoxx-france-2012-english-version)

Look at slide #13

HTH

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 23 déc. 2012 à 07:54, JD [jdalecki@tycoint.com](mailto:jdalecki@tycoint.com) a écrit :

Hi Rafał,  
Getting back to the “Elasticsearch in 5 minutes“ - [http://www.elasticsearchtutorial.com/elasticsearch-in-5-minutes.html](http://www.elasticsearchtutorial.com/elasticsearch-in-5-minutes.html).  
When they execute:

curl -XPUT '[http://localhost:9200/blog/post/1](http://localhost:9200/blog/post/1)' -d '  
{  
"user": "dilbert",  
"postDate": "2011-12-15",  
"body": "Search is hard. Search should be easy." ,  
"title": "On search"  
}

It creates in the Elasticsearch db a record:

{  
"\_index": "blog",  
"\_type": "post",  
"\_id": "1",  
"\_version": 1,  
"exists": true,  
"\_source": {  
"user": "dilbert",  
"postDate": "2011-12-15",  
"body": "Search is hard. Search should be easy.",  
"title": "On search"  
}  
}  
I can’t understand why the “blog” word from path becomes a “\_index”, the “post” word becomes a “\_type” and the “1” becomes a “\_id”. Is this explained anywhere. I am not asking you to explain it all to me, but would appreciate if you could refer me to a good tutorial that explains how the url path components map to the record fields in the elasticsearch db. Also Java examples would be great to look at.  
Regards,  
Janusz

On Friday, December 21, 2012 7:52:14 PM UTC+11, JD wrote:

> Hi Everybody,  
> I am trying to use elasticsearch from Java. (I am running elasticsearch  
> server locally on my laptop using java 6 in Windows 7 64 bits and the client  
> under eclipse Indigo)  
> First of all I have followed the tutorial “Elasticsearch in 5 minutes” and I  
> created a few indexed data as per tutorial. (e.i.  
> [http://localhost:9200/blog/post/1](http://localhost:9200/blog/post/1) (in particular “Dilbert Brown” item -  
> using postman [http://localhost:9200/blog/user/dilbert](http://localhost:9200/blog/user/dilbert)' '{ "name" : "Dilbert  
> Brown" }').
> 
> I have checked that the record and it does exist – using again postman util.  
> Everything works fine from dos command prompt – as described by the tutorial  
> My question is: how do I retrieve it from elasticsearch using Java. I have  
> tried this code?  
> Client client = new TransportClient().addTransportAddress(new  
> InetSocketTransportAddress("localhost", 9200));  
> SearchResponse response =  
> client.prepareSearch("mongoindex").setSearchType(
> 
> SearchType.DFS\_QUERY\_THEN\_FETCH).setQuery(QueryBuilders.termQuery("name",  
> "Dilbert Brown"))  
> .setFrom(0).setSize(60).setExplain(true).execute().actionGet();
> 
> ```
> SearchHit[] docs = response.getHits().getHits(); 
> 
> ```
> 
> From prepareSearch method I am getting:
> 
> org.elasticsearch.client.transport.NoNodeAvailableException: No node  
> available  
> at  
> org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:205)  
> at  
> org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:97)  
> at  
> org.elasticsearch.client.support.AbstractClient.search(AbstractClient.java:206)  
> at  
> org.elasticsearch.client.transport.TransportClient.search(TransportClient.java:365)  
> at  
> org.elasticsearch.action.search.SearchRequestBuilder.doExecute(SearchRequestBuilder.java:743)  
> at  
> org.elasticsearch.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:53)  
> at  
> org.elasticsearch.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:47)  
> at  
> com.tycoint.eams.servlet.InitContextListener.contextInitialized(InitContextListener.java:94)  
> at  
> org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)  
> at  
> org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)  
> at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)  
> at  
> org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)  
> at  
> org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)  
> at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)  
> at java.util.concurrent.FutureTask.run(FutureTask.java:138)  
> at  
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  
> at  
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  
> at java.lang.Thread.run(Thread.java:662)
> 
> What Am I doing wrong?  
> Regards,  
> Janusz
> 
> --  
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/How-to-retrieve-elasticsearch-Data-from-Java-application-tp4027312.html](http://elasticsearch-users.115913.n3.nabble.com/How-to-retrieve-elasticsearch-Data-from-Java-application-tp4027312.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).  
> --

--

---

<div class="post-metadata">

**Author:** ![Janusz\_Dalecki](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Janusz\_Dalecki](https://discuss.elastic.co/u/Janusz_Dalecki)\
**Post date:** [December 23, 2012, 9:16am UTC](https://discuss.elastic.co/t/how-to-retrieve-elasticsearch-data-from-java-application/10148/12 "2012-12-23T09:16:25Z")

</div>

David,

That's pretty impressive, do you have printable version?

Regards,

Janusz

On Friday, December 21, 2012 7:52:14 PM UTC+11, JD wrote:

> Hi Everybody,  
> I am trying to use elasticsearch from Java. (I am running elasticsearch  
> server locally on my laptop using java 6 in Windows 7 64 bits and the  
> client  
> under eclipse Indigo)  
> First of all I have followed the tutorial “Elasticsearch in 5 minutes” and  
> I  
> created a few indexed data as per tutorial. (e.i.  
> [http://localhost:9200/blog/post/1](http://localhost:9200/blog/post/1) (in particular “Dilbert Brown” item -  
> using postman [http://localhost:9200/blog/user/dilbert](http://localhost:9200/blog/user/dilbert)' '{ "name" :  
> "Dilbert  
> Brown" }').
> 
> I have checked that the record and it does exist – using again postman  
> util.  
> Everything works fine from dos command prompt – as described by the  
> tutorial  
> My question is: how do I retrieve it from elasticsearch using Java. I have  
> tried this code?  
> Client client = new TransportClient().addTransportAddress(new  
> InetSocketTransportAddress("localhost", 9200));  
> SearchResponse response =  
> client.prepareSearch("mongoindex").setSearchType(
> 
> SearchType.DFS\_QUERY\_THEN\_FETCH).setQuery(QueryBuilders.termQuery("name",  
> "Dilbert Brown"))  
> .setFrom(0).setSize(60).setExplain(true).execute().actionGet();
> 
> ```
> SearchHit[] docs = response.getHits().getHits(); 
> 
> ```
> 
> From prepareSearch method I am getting:
> 
> org.elasticsearch.client.transport.NoNodeAvailableException: No node  
> available  
> at  
> org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:205)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:97)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.client.support.AbstractClient.search(AbstractClient.java:206)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.client.transport.TransportClient.search(TransportClient.java:365)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.action.search.SearchRequestBuilder.doExecute(SearchRequestBuilder.java:743)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:53)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:47)
> 
> ```
> at 
> 
> ```
> 
> com.tycoint.eams.servlet.InitContextListener.contextInitialized(InitContextListener.java:94)
> 
> ```
> at 
> 
> ```
> 
> org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
> 
> ```
> at 
> 
> ```
> 
> org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
> 
> ```
> at 
> 
> ```
> 
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)  
> at  
> org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
> 
> ```
> at 
> 
> ```
> 
> org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
> 
> ```
> at 
> 
> ```
> 
> java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)  
> at java.util.concurrent.FutureTask.run(FutureTask.java:138)  
> at  
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
> 
> ```
> at 
> 
> ```
> 
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
> 
> ```
> at java.lang.Thread.run(Thread.java:662) 
> 
> ```
> 
> What Am I doing wrong?  
> Regards,  
> Janusz
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/How-to-retrieve-elasticsearch-Data-from-Java-application-tp4027312.html](http://elasticsearch-users.115913.n3.nabble.com/How-to-retrieve-elasticsearch-Data-from-Java-application-tp4027312.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--

---

<div class="post-metadata">

**Author:** ![Janusz\_Dalecki](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Janusz\_Dalecki](https://discuss.elastic.co/u/Janusz_Dalecki)\
**Post date:** [December 25, 2012, 6:52am UTC](https://discuss.elastic.co/t/how-to-retrieve-elasticsearch-data-from-java-application/10148/13 "2012-12-25T06:52:25Z")

</div>

I have previously asked a question about “Elasticsearch in 5 minutes”  
example and why the code below does not return any result (it throws a NoNodeAvailableException  
exception):

Client client = new TransportClient().addTransportAddress(new

InetSocketTransportAddress("localhost", 9200));

```
  SearchResponse response =

```

client.prepareSearch("mongoindex").setSearchType(

SearchType.DFS\_QUERY\_THEN\_FETCH).setQuery(QueryBuilders.termQuery("name",

"Dilbert  
Brown")).setFrom(0).setSize(60).setExplain(true).execute().actionGet();

```
  SearchHit[] docs = response.getHits().getHits();

```

Ivan has pointed out that a term query is not analyzed, while the name  
field is.

I did use a matching query and it does work – however I still don’t  
understand the term query.

When would a term query work in this example.

Can somebody explain this in details, please?

On Friday, December 21, 2012 7:52:14 PM UTC+11, JD wrote:

> Hi Everybody,  
> I am trying to use elasticsearch from Java. (I am running elasticsearch  
> server locally on my laptop using java 6 in Windows 7 64 bits and the  
> client  
> under eclipse Indigo)  
> First of all I have followed the tutorial “Elasticsearch in 5 minutes” and  
> I  
> created a few indexed data as per tutorial. (e.i.  
> [http://localhost:9200/blog/post/1](http://localhost:9200/blog/post/1) (in particular “Dilbert Brown” item -  
> using postman [http://localhost:9200/blog/user/dilbert](http://localhost:9200/blog/user/dilbert)' '{ "name" :  
> "Dilbert  
> Brown" }').  
> Regards,

Janusz

> I have checked that the record and it does exist – using again postman  
> util.  
> Everything works fine from dos command prompt – as described by the  
> tutorial  
> My question is: how do I retrieve it from elasticsearch using Java. I have  
> tried this code?  
> Client client = new TransportClient().addTransportAddress(new  
> InetSocketTransportAddress("localhost", 9200));  
> SearchResponse response =  
> client.prepareSearch("mongoindex").setSearchType(
> 
> SearchType.DFS\_QUERY\_THEN\_FETCH).setQuery(QueryBuilders.termQuery("name",  
> "Dilbert Brown"))  
> .setFrom(0).setSize(60).setExplain(true).execute().actionGet();
> 
> ```
> SearchHit[] docs = response.getHits().getHits(); 
> 
> ```
> 
> From prepareSearch method I am getting:
> 
> org.elasticsearch.client.transport.NoNodeAvailableException: No node  
> available  
> at  
> org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:205)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:97)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.client.support.AbstractClient.search(AbstractClient.java:206)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.client.transport.TransportClient.search(TransportClient.java:365)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.action.search.SearchRequestBuilder.doExecute(SearchRequestBuilder.java:743)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:53)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:47)
> 
> ```
> at 
> 
> ```
> 
> com.tycoint.eams.servlet.InitContextListener.contextInitialized(InitContextListener.java:94)
> 
> ```
> at 
> 
> ```
> 
> org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
> 
> ```
> at 
> 
> ```
> 
> org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
> 
> ```
> at 
> 
> ```
> 
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)  
> at  
> org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
> 
> ```
> at 
> 
> ```
> 
> org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
> 
> ```
> at 
> 
> ```
> 
> java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)  
> at java.util.concurrent.FutureTask.run(FutureTask.java:138)  
> at  
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
> 
> ```
> at 
> 
> ```
> 
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
> 
> ```
> at java.lang.Thread.run(Thread.java:662) 
> 
> ```
> 
> What Am I doing wrong?  
> Regards,  
> Janusz
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/How-to-retrieve-elasticsearch-Data-from-Java-application-tp4027312.html](http://elasticsearch-users.115913.n3.nabble.com/How-to-retrieve-elasticsearch-Data-from-Java-application-tp4027312.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--

---

<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:** [December 25, 2012, 7:32pm UTC](https://discuss.elastic.co/t/how-to-retrieve-elasticsearch-data-from-java-application/10148/14 "2012-12-25T19:32:36Z")

</div>

The analysis concepts of Elasticsearch comes directly from Lucene, so you  
can learn more by reading up on Lucene.

When you define your mapping, you can set a field to be analyzed or  
not\_analyzed:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

not\_analyzed fields do not go through analysis, which means tokenization,  
filtering and other text analysis. The values remain as is. The default is  
for fields to be analyzed. The search string for term queries are not  
analyzed, so they are only useful for searching against fields that are  
not\_analyzed. If you want to search against a field that was analyzed, you  
need to use a query that will also analyze the search terms (using the same  
analyzer preferably).

You can use the Analyze API to see the Analyzer in action:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

The keyword analyzer is similar to not using any analyzer.

Cheers,

Ivan

On Mon, Dec 24, 2012 at 10:52 PM, JD [jdalecki@tycoint.com](mailto:jdalecki@tycoint.com) wrote:

> I did use a matching query and it does work – however I still don’t  
> understand the term query.\*\*\*\*
> 
> When would a term query work in this example.\*\*\*\*
> 
> Can somebody explain this in details, please?

--

---

<div class="post-metadata">

**Author:** ![Srikanth\_gone](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@Srikanth\_gone](https://discuss.elastic.co/u/Srikanth_gone)\
**Post date:** [March 11, 2013, 8:05am UTC](https://discuss.elastic.co/t/how-to-retrieve-elasticsearch-data-from-java-application/10148/15 "2013-03-11T08:05:03Z")

</div>

Hi All,

How to search specific text using Elasticsearch in java

this is my code..

Settings settings = ImmutableSettings.

> settingsBuilder()  
> .put("http.enabled", "false")  
> .put("transport.tcp.port", "9300-9400")  
> .put("discovery.zen.ping.multicast.enabled", "false")  
> .put("discovery.zen.ping.unicast.hosts", "localhost").build();
> 
> ```
> Node node = 
> 
> ```
> 
> NodeBuilder.nodeBuilder().client(true).settings(settings).clusterName("elasticsearch").node();  
> client = node.client();
> 
> ```
> QueryBuilder queryBuilder = QueryBuilders.termQuery("userName", 
> 
> ```
> 
> "SampleUser");  
> SearchRequestBuilder searchRequestBuilder =  
> client.prepareSearch("\_river");  
> searchRequestBuilder.setTypes("dc\_user\_river");  
> searchRequestBuilder.setSearchType(SearchType.DFS\_QUERY\_AND\_FETCH);  
> searchRequestBuilder.setQuery(queryBuilder);  
> searchRequestBuilder.setFrom(0).setSize(60).setExplain(true);  
> SearchResponse resp = searchRequestBuilder.execute().actionGet();  
> System.out.println(resp);  
> for (SearchHit hit : resp.getHits())  
> System.out.println("Hit ID: "+hit.getId());  
> node.close();
> 
> output :  
> {  
> "took" : 32,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 1,  
> "successful" : 1,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 0,  
> "max\_score" : null,  
> "hits" :   
> }  
> }
> 
> i am getting 0 records.. is there any thing missing..

if i am using browser

[http://192.168.10.2:9200/\_river/dc\_user\_river/\_search?pretty=true](http://192.168.10.2:9200/_river/dc_user_river/_search?pretty=true)

output:

{  
"took" : 16,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 1,  
"successful" : 1,  
"failed" : 0  
},  
"hits" : {  
"total" : 2,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "\_river",  
"\_type" : "dc\_user\_river",  
"\_id" : "\_status",  
"\_score" : 1.0, "\_source" : {"ok":true,"node":{"id":"5jzC7AsUTCKdHCUcob6TsA","name":"Volstagg","transport\_address":"inet[/192.168.10.2:9300]"}}  
}, {  
"\_index" : "\_river",  
"\_type" : "dc\_user\_river",  
"\_id" : "\_meta",  
"\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb": { "db": "data-collection", "collection": "DC\_USER" }, "index": { "name": "dc\_user\_idx", "type": "DC\_USER" }}  
} ]  
}  
}

how to get records using java Elasticsearch..

please any one help me.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [March 11, 2013, 8:29am UTC](https://discuss.elastic.co/t/how-to-retrieve-elasticsearch-data-from-java-application/10148/16 "2013-03-11T08:29:28Z")

</div>

srikanth,

please start your own thread. Don't hijack others threads! You won't get  
good responses neither will anybody bother jumping in.

please start a new thread,

simon

On Monday, March 11, 2013 9:05:03 AM UTC+1, srikanth gone wrote:

> Hi All,
> 
> How to search specific text using Elasticsearch in java
> 
> this is my code..
> 
> Settings settings = ImmutableSettings.
> 
> > settingsBuilder()  
> > .put("http.enabled", "false")  
> > .put("transport.tcp.port", "9300-9400")  
> > .put("discovery.zen.ping.multicast.enabled", "false")  
> > .put("discovery.zen.ping.unicast.hosts", "localhost").build();
> > 
> > ```
> > Node node = 
> > 
> > ```
> > 
> > NodeBuilder.nodeBuilder().client(true).settings(settings).clusterName("elasticsearch").node();  
> > client = node.client();
> > 
> > ```
> > QueryBuilder queryBuilder = QueryBuilders.termQuery("userName", 
> > 
> > ```
> > 
> > "SampleUser");  
> > SearchRequestBuilder searchRequestBuilder =  
> > client.prepareSearch("\_river");  
> > searchRequestBuilder.setTypes("dc\_user\_river");
> > 
> > searchRequestBuilder.setSearchType(SearchType.DFS\_QUERY\_AND\_FETCH);  
> > searchRequestBuilder.setQuery(queryBuilder);  
> > searchRequestBuilder.setFrom(0).setSize(60).setExplain(true);  
> > SearchResponse resp = searchRequestBuilder.execute().actionGet();  
> > System.out.println(resp);  
> > for (SearchHit hit : resp.getHits())  
> > System.out.println("Hit ID: "+hit.getId());  
> > node.close();
> > 
> > output :  
> > {  
> > "took" : 32,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 1,  
> > "successful" : 1,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 0,  
> > "max\_score" : null,  
> > "hits" :   
> > }  
> > }
> > 
> > i am getting 0 records.. is there any thing missing..
> 
> if i am using browser
> 
> [http://192.168.10.2:9200/\_river/dc\_user\_river/\_search?pretty=true](http://192.168.10.2:9200/_river/dc_user_river/_search?pretty=true)
> 
> output:
> 
> {  
> "took" : 16,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 1,  
> "successful" : 1,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 2,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "\_river",  
> "\_type" : "dc\_user\_river",  
> "\_id" : "\_status",  
> "\_score" : 1.0, "\_source" : {"ok":true,"node":{"id":"5jzC7AsUTCKdHCUcob6TsA","name":"Volstagg","transport\_address":"inet[/192.168.10.2:9300]"}}  
> }, {  
> "\_index" : "\_river",  
> "\_type" : "dc\_user\_river",  
> "\_id" : "\_meta",  
> "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb": { "db": "data-collection", "collection": "DC\_USER" }, "index": { "name": "dc\_user\_idx", "type": "DC\_USER" }}  
> } ]  
> }  
> }
> 
> how to get records using java Elasticsearch..
> 
> please any one help me.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 6, 2017, 2:47am UTC](https://discuss.elastic.co/t/how-to-retrieve-elasticsearch-data-from-java-application/10148/17 "2017-07-06T02:47:16Z")

</div>


