Using ES with Java API

Hello ES community,

I am new to ES and try to build my head around it :slight_smile:
I think I am going to use ES for my project, so I am going
to do some unittests for me.

ES looks on one hand easy to use but on the other hand
I do not know where to get startet.

Since I do not need now to have a seperate search server
I would like to use ES from within my Scala app.

I have placed a elasticsearch.json file in my "resources" dir,
so it will be on the classpath.

Is it sufficient to just get a
NodeBuilder.nodeBuilder().node().client()
and work with it? Or is there another step that I am missing?
Here is an info http://www.elasticsearch.org/guide/reference/java-api/client.html
that for unittest I need to set a node as "local" so that it can
connect to a local node.
That confused me a bit.

best regards

you would want to keep the Node returned around as well (and keep it at the application score). And then, when the application stops / closes, call close on it. Other than that, looks good.
On Friday, May 20, 2011 at 1:32 PM, greekscala wrote:
Hello ES community,

I am new to ES and try to build my head around it :slight_smile:
I think I am going to use ES for my project, so I am going
to do some unittests for me.

ES looks on one hand easy to use but on the other hand
I do not know where to get startet.

Since I do not need now to have a seperate search server
I would like to use ES from within my Scala app.

I have placed a elasticsearch.json file in my "resources" dir,
so it will be on the classpath.

Is it sufficient to just get a
NodeBuilder.nodeBuilder().node().client()
and work with it? Or is there another step that I am missing?
Here is an info Elasticsearch Platform — Find real-time answers at scale | Elastic
that for unittest I need to set a node as "local" so that it can
connect to a local node.
That confused me a bit.

best regards

Hello Shay,

thank you for answering. So I should use a singleton Node, once a Node
is obtained.

thanks.

best regards

On 20 Mai, 13:51, Shay Banon shay.ba...@elasticsearch.com wrote:

you would want to keep the Node returned around as well (and keep it at the application score). And then, when the application stops / closes, call close on it. Other than that, looks good.On Friday, May 20, 2011 at 1:32 PM, greekscala wrote:

Hello ES community,

I am new to ES and try to build my head around it :slight_smile:
I think I am going to use ES for my project, so I am going
to do some unittests for me.

ES looks on one hand easy to use but on the other hand
I do not know where to get startet.

Since I do not need now to have a seperate search server
I would like to use ES from within my Scala app.

I have placed a elasticsearch.json file in my "resources" dir,
so it will be on the classpath.

Is it sufficient to just get a
NodeBuilder.nodeBuilder().node().client()
and work with it? Or is there another step that I am missing?
Here is an infohttp://www.elasticsearch.org/guide/reference/java-api/client.html
that for unittest I need to set a node as "local" so that it can
connect to a local node.
That confused me a bit.

best regards

Just found this:
http://groups.google.com/a/elasticsearch.com/group/users/browse_thread/thread/a618d990927c6756/1896faf0e22771d9?lnk=gst&q=spring#1896faf0e22771d9

Think will take the Spring approach, too.

best reagards

On 20 Mai, 15:52, greekscala hellectro...@gmail.com wrote:

Hello Shay,

thank you for answering. So I should use a singleton Node, once a Node
is obtained.

thanks.

best regards

On 20 Mai, 13:51, Shay Banon shay.ba...@elasticsearch.com wrote:

you would want to keep the Node returned around as well (and keep it at the application score). And then, when the application stops / closes, call close on it. Other than that, looks good.On Friday, May 20, 2011 at 1:32 PM, greekscala wrote:

Hello ES community,

I am new to ES and try to build my head around it :slight_smile:
I think I am going to use ES for my project, so I am going
to do some unittests for me.

ES looks on one hand easy to use but on the other hand
I do not know where to get startet.

Since I do not need now to have a seperate search server
I would like to use ES from within my Scala app.

I have placed a elasticsearch.json file in my "resources" dir,
so it will be on the classpath.

Is it sufficient to just get a
NodeBuilder.nodeBuilder().node().client()
and work with it? Or is there another step that I am missing?
Here is an infohttp://www.elasticsearch.org/guide/reference/java-api/client.html
that for unittest I need to set a node as "local" so that it can
connect to a local node.
That confused me a bit.

best regards

greekscala skrev 2011-05-20 15:56:

Just found this:
http://groups.google.com/a/elasticsearch.com/group/users/browse_thread/thread/a618d990927c6756/1896faf0e22771d9?lnk=gst&q=spring#1896faf0e22771d9

Think will take the Spring approach, too.

best reagards

I found that having ES run as a service has many benefits. Scaling is
one since clustrering support is kind of built-in. And having many
different indexes running on the same server etc.
Running tests and queries is also easier on a standalons server.
But for a small application an embedded solution might work.

When it comes to coding the Java API I found the simplest solution was
to download the source and look at the plethora of unit tests that are
in there. They are the true bluerprint of what the API can do. The docs
where (at the time I started coding) a bit lacking...

Regards
Kristian

Hello Kristian,

thank you for your comment. I think that I will need an ES-Server
in the future. But for now I think that I will try to use ES as
embedded.

The idea with the unit tests is a good one. Will clone the repository
and take a look.

Just to be complete. The link above to the spring solution helped.
I just created a bean with postConstruct and preDestroy annotations:
@Service
class SearchServiceESImpl extends SearchService {

private var node: Node = _

@PostConstruct
def start() {
node = NodeBuilder.nodeBuilder.node
}

@PreDestroy
def stop() {
node.close
}

def client() = node.client
}

with best regards

On 24 Mai, 09:10, Kristian Jörg k...@devo.se wrote:

greekscala skrev 2011-05-20 15:56:

Just found this:
http://groups.google.com/a/elasticsearch.com/group/users/browse_threa...

Think will take the Spring approach, too.

best reagards

I found that having ES run as a service has many benefits. Scaling is
one since clustrering support is kind of built-in. And having many
different indexes running on the same server etc.
Running tests and queries is also easier on a standalons server.
But for a small application an embedded solution might work.

When it comes to coding the Java API I found the simplest solution was
to download the source and look at the plethora of unit tests that are
in there. They are the true bluerprint of what the API can do. The docs
where (at the time I started coding) a bit lacking...

Regards
Kristian

Hello again.

Yes, that Spring solution is what I use myself. In a simple servlet
there are the standard init and destroy methods as well that can be
used in similar manner.

/Kristian

greekscala skrev 2011-05-31 23:29:

Hello Kristian,

thank you for your comment. I think that I will need an ES-Server
in the future. But for now I think that I will try to use ES as
embedded.

The idea with the unit tests is a good one. Will clone the repository
and take a look.

Just to be complete. The link above to the spring solution helped.
I just created a bean with postConstruct and preDestroy annotations:
@Service
class SearchServiceESImpl extends SearchService {

private var node: Node = _

@PostConstruct
def start() {
node = NodeBuilder.nodeBuilder.node
}

@PreDestroy
def stop() {
node.close
}

def client() = node.client
}

with best regards

On 24 Mai, 09:10, Kristian Jörgk...@devo.se wrote:

greekscala skrev 2011-05-20 15:56:

Just found this:
http://groups.google.com/a/elasticsearch.com/group/users/browse_threa...
Think will take the Spring approach, too.
best reagards
I found that having ES run as a service has many benefits. Scaling is
one since clustrering support is kind of built-in. And having many
different indexes running on the same server etc.
Running tests and queries is also easier on a standalons server.
But for a small application an embedded solution might work.

When it comes to coding the Java API I found the simplest solution was
to download the source and look at the plethora of unit tests that are
in there. They are the true bluerprint of what the API can do. The docs
where (at the time I started coding) a bit lacking...

Regards
Kristian