How to retrieve elasticsearch Data from Java application

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 (in particular “Dilbert Brown” item - using postman 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

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/ :: 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 (in particular "Dilbert Brown" item -
using postman 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
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

--

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

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/ :: 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
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

--

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). 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/ :: 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

Sent from the Elasticsearch Users mailing list archive at Nabble.com.

--

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). 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 (in particular “Dilbert Brown” item -
using postman 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
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

--

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 wrote:

Dilbert

--

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 (in particular “Dilbert Brown” item -
using postman 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
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

--

Hello!

Try looking at the query DSL and a query type you are interested in - 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

--

Regards,

Rafał Kuć

Sematext :: 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/post/1 (in particular “Dilbert Brown” item -

using postman 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

Sent from the ElasticSearch Users mailing list archive at Nabble.com.

--

Hi Rafał,

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

When they execute:

curl -XPUT '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 (in particular "Dilbert Brown" item -
using postman 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
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

--

Have a look at my devoxx France (english translated) slides : Elasticsearch - Devoxx France 2012 - English version | PPT

Look at slide #13

HTH

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

Le 23 déc. 2012 à 07:54, JD jdalecki@tycoint.com a écrit :

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

curl -XPUT '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 (in particular “Dilbert Brown” item -
using postman 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
Sent from the Elasticsearch Users mailing list archive at Nabble.com.
--

--

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 (in particular “Dilbert Brown” item -
using postman 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
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

--

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 (in particular “Dilbert Brown” item -
using postman 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
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

--

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:

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:

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 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?

--

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

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.
For more options, visit https://groups.google.com/groups/opt_out.

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

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.
For more options, visit https://groups.google.com/groups/opt_out.