A simple example of how to use the Java API?

I am completely new to Elastic Search. I have figured out enough that I can
retrieve jsons from our cluster with:

-bash-3.2$ curl -XGET http://10.10.1.7:9200/twitter-sept/_search -d
'{"query":{"bool":{"must":[{"term":{"tweet":"elastic"}}],"must_not":[],"should":[]}},"from":0,"size":50,"sort":[],"facets":{}}'

Since most of my code is in Java I figured things would be easier if I used
the Java API. I am completely stumped on how to do it. The guide
http://www.elasticsearch.org/guide/reference/java-api/search.html is
confusing. What are all those classes? Where are the javadocs? Is there a
simple example somewhere that explains how I can reproduce the above
command in Java? Do I need a TransportClient, a SearchSourceBuilder,
ImmutableSettings?

--

Hi Ryan,

Have a look at this: https://github.com/elasticsearchfr/hands-on
Answers are on answers branch: https://github.com/elasticsearchfr/hands-on/tree/answers

Some slides (in french but you can understand code) are here: http://www.slideshare.net/mobile/dadoonet/hands-on-lab-elasticsearch

I'm waiting for ES team to merge my Java tutorial: https://github.com/elasticsearch/elasticsearch.github.com/pull/321
It will look like this: https://github.com/dadoonet/elasticsearch.github.com/blob/9f6dae922247a81f1c72c77769d1dce3ad09dca5/tutorials/_posts/2012-11-07-using-java-api-basics.markdown

HTH

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

Le 15 nov. 2012 à 04:04, ryan compton compton.ryan@gmail.com a écrit :

I am completely new to Elastic Search. I have figured out enough that I can retrieve jsons from our cluster with:

-bash-3.2$ curl -XGET http://10.10.1.7:9200/twitter-sept/_search -d '{"query":{"bool":{"must":[{"term":{"tweet":"elastic"}}],"must_not":[],"should":[]}},"from":0,"size":50,"sort":[],"facets":{}}'

Since most of my code is in Java I figured things would be easier if I used the Java API. I am completely stumped on how to do it. The guide http://www.elasticsearch.org/guide/reference/java-api/search.html is confusing. What are all those classes? Where are the javadocs? Is there a simple example somewhere that explains how I can reproduce the above command in Java? Do I need a TransportClient, a SearchSourceBuilder, ImmutableSettings?

--

Not sure that my answer was posted. :frowning: I'm reposting here.

Hi Ryan,

Have a look at this: https://github.com/elasticsearchfr/hands-on
Answers are on answers branch: https://github.com/elasticsearchfr/hands-on/tree/answers

Some slides (in french but you can understand code) are here: http://www.slideshare.net/mobile/dadoonet/hands-on-lab-elasticsearch

I'm waiting for ES team to merge my Java tutorial: https://github.com/elasticsearch/elasticsearch.github.com/pull/321
It will look like this: https://github.com/dadoonet/elasticsearch.github.com/blob/9f6dae922247a81f1c72c77769d1dce3ad09dca5/tutorials/_posts/2012-11-07-using-java-api-basics.markdown

HTH

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

Le 15 nov. 2012 à 04:04, ryan compton compton.ryan@gmail.com a écrit :

I am completely new to Elastic Search. I have figured out enough that I can retrieve jsons from our cluster with:

-bash-3.2$ curl -XGET http://10.10.1.7:9200/twitter-sept/_search -d '{"query":{"bool":{"must":[{"term":{"tweet":"elastic"}}],"must_not":[],"should":[]}},"from":0,"size":50,"sort":[],"facets":{}}'

Since most of my code is in Java I figured things would be easier if I used the Java API. I am completely stumped on how to do it. The guide http://www.elasticsearch.org/guide/reference/java-api/search.html is confusing. What are all those classes? Where are the javadocs? Is there a simple example somewhere that explains how I can reproduce the above command in Java? Do I need a TransportClient, a SearchSourceBuilder, ImmutableSettings?

--

Not sure that my answer was posted. :frowning: I'm reposting here.
Something goes wrong with the mailing list or do I have a problem on my side?

(Sorry for the disturb)

Hi Ryan,

Have a look at this: https://github.com/elasticsearchfr/hands-on
Answers are on answers branch: https://github.com/elasticsearchfr/hands-on/tree/answers

Some slides (in french but you can understand code) are here: http://www.slideshare.net/mobile/dadoonet/hands-on-lab-elasticsearch

I'm waiting for ES team to merge my Java tutorial: https://github.com/elasticsearch/elasticsearch.github.com/pull/321
It will look like this: https://github.com/dadoonet/elasticsearch.github.com/blob/9f6dae922247a81f1c72c77769d1dce3ad09dca5/tutorials/_posts/2012-11-07-using-java-api-basics.markdown

HTH

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

Le 15 nov. 2012 à 04:04, ryan compton compton.ryan@gmail.com a écrit :

I am completely new to Elastic Search. I have figured out enough that I can retrieve jsons from our cluster with:

-bash-3.2$ curl -XGET http://10.10.1.7:9200/twitter-sept/_search -d '{"query":{"bool":{"must":[{"term":{"tweet":"elastic"}}],"must_not":[],"should":[]}},"from":0,"size":50,"sort":[],"facets":{}}'

Since most of my code is in Java I figured things would be easier if I used the Java API. I am completely stumped on how to do it. The guide http://www.elasticsearch.org/guide/reference/java-api/search.html is confusing. What are all those classes? Where are the javadocs? Is there a simple example somewhere that explains how I can reproduce the above command in Java? Do I need a TransportClient, a SearchSourceBuilder, ImmutableSettings?

--

Hi Ryan,

Have a look at this: https://github.com/elasticsearchfr/hands-on
Answers are on answers branch: https://github.com/elasticsearchfr/hands-on/tree/answers

Some slides (in french but you can understand code) are here: http://www.slideshare.net/mobile/dadoonet/hands-on-lab-elasticsearch

I'm waiting for ES team to merge my Java tutorial: https://github.com/elasticsearch/elasticsearch.github.com/pull/321
It will look like this: https://github.com/dadoonet/elasticsearch.github.com/blob/9f6dae922247a81f1c72c77769d1dce3ad09dca5/tutorials/_posts/2012-11-07-using-java-api-basics.markdown

HTH

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

--

Thanks!

I can finally get some basic searches working from Java now. After looking
through some of that code I can run the simple example below. I'm sure
there are reasons I should bother with TransportClients, setting cluster
names (ours is not "elasticsearch"), etc.. But for just getting started
and making sure things work the code in the tutorial really helped. I wish
the guide at
Elasticsearch Platform — Find real-time answers at scale | Elastic had
actual code and not just snippets.

public static void main(String args){
Node node = NodeBuilder.nodeBuilder().node();
Assert.assertNotNull(node);
Assert.assertFalse(node.isClosed());

QueryBuilder qb = QueryBuilders.termQuery("tweet", "elastic");

SearchResponse sr = node.client().prepareSearch()
.setQuery(qb)
.execute()
.actionGet();
Assert.assertNotNull(sr);
Assert.assertNotNull(sr.getHits());
Assert.assertTrue(sr.getHits().getTotalHits() > 0);
java.util.Iterator hit_it = sr.getHits().iterator();
while(hit_it.hasNext()){
SearchHit hit = hit_it.next();
System.out.println(hit.getSourceAsString());
}
}

On Thursday, November 15, 2012 2:10:27 AM UTC-8, David Pilato wrote:

Not sure that my answer was posted. :frowning: I'm reposting here.

Hi Ryan,

Have a look at this: GitHub - elasticsearchfr/hands-on: Hands On Lab
Answers are on answers branch:
GitHub - elasticsearchfr/hands-on at answers

Some slides (in french but you can understand code) are here:
Hands on lab Elasticsearch | PPT

I'm waiting for ES team to merge my Java tutorial:
https://github.com/elasticsearch/elasticsearch.github.com/pull/321
It will look like this:
https://github.com/dadoonet/elasticsearch.github.com/blob/9f6dae922247a81f1c72c77769d1dce3ad09dca5/tutorials/_posts/2012-11-07-using-java-api-basics.markdown

HTH

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

Le 15 nov. 2012 à 04:04, ryan compton <compto...@gmail.com <javascript:>>
a écrit :

I am completely new to Elastic Search. I have figured out enough that I
can retrieve jsons from our cluster with:

-bash-3.2$ curl -XGET http://10.10.1.7:9200/twitter-sept/_search -d
'{"query":{"bool":{"must":[{"term":{"tweet":"elastic"}}],"must_not":,"should":}},"from":0,"size":50,"sort":,"facets":{}}'

Since most of my code is in Java I figured things would be easier if I
used the Java API. I am completely stumped on how to do it. The guide
Elasticsearch Platform — Find real-time answers at scale | Elastic is
confusing. What are all those classes? Where are the javadocs? Is there a
simple example somewhere that explains how I can reproduce the above
command in Java? Do I need a TransportClient, a SearchSourceBuilder,
ImmutableSettings?

--

--

ryan compton wrote:

Since most of my code is in Java I figured things would be easier
if I used the Java API. I am completely stumped on how to do
it.

Hi Ryan! I heartily recommend reading the tests in IntelliJ. That's
how I usually figure out what was intended in the Java API. The
coverage of the search API is pretty robust.

-Drew

--

Hey David,

I'm looking at the code now and I see lots of TODOs and nulls, but no
actual indexing. Perhaps that code needs to be cleaned up?

On Thursday, November 15, 2012 at 9:11:02 AM UTC-5, David Pilato wrote:

Hi Ryan,

Have a look at this: GitHub - elasticsearchfr/hands-on: Hands On Lab
Answers are on answers branch:
GitHub - elasticsearchfr/hands-on at answers

Some slides (in french but you can understand code) are here:
Hands on lab Elasticsearch | PPT

I'm waiting for ES team to merge my Java tutorial:
https://github.com/elasticsearch/elasticsearch.github.com/pull/321
It will look like this:
https://github.com/dadoonet/elasticsearch.github.com/blob/9f6dae922247a81f1c72c77769d1dce3ad09dca5/tutorials/_posts/2012-11-07-using-java-api-basics.markdown

HTH

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

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/92c7a0f5-ef47-45c2-b121-8c0302fa8c71%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Did you look at answer branch?

Answers are on answers branch: GitHub - elasticsearchfr/hands-on at answers

David

Le 24 mars 2015 à 12:58, 'newbo' via elasticsearch elasticsearch@googlegroups.com a écrit :

Hey David,

I'm looking at the code now and I see lots of TODOs and nulls, but no actual indexing. Perhaps that code needs to be cleaned up?

On Thursday, November 15, 2012 at 9:11:02 AM UTC-5, David Pilato wrote:

Hi Ryan,

Have a look at this: GitHub - elasticsearchfr/hands-on: Hands On Lab
Answers are on answers branch: GitHub - elasticsearchfr/hands-on at answers

Some slides (in french but you can understand code) are here: Hands on lab Elasticsearch | PPT

I'm waiting for ES team to merge my Java tutorial: https://github.com/elasticsearch/elasticsearch.github.com/pull/321
It will look like this: https://github.com/dadoonet/elasticsearch.github.com/blob/9f6dae922247a81f1c72c77769d1dce3ad09dca5/tutorials/_posts/2012-11-07-using-java-api-basics.markdown

HTH

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

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/92c7a0f5-ef47-45c2-b121-8c0302fa8c71%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/F32F4B0D-3A65-45C6-BC95-19608C8AE62B%40pilato.fr.
For more options, visit https://groups.google.com/d/optout.

So where is a good java example showing how to use the java api to do a
simple and condition. I can get this to work work fine with curl but how do
I use the java api to implement it.

curl -XPOST 10.20.71.30:9200/sessionmsg/_search?pretty -d '{
"query": {
"bool": {
"must": [
{
"term": {
"roomid": "7087"
}
},
{
"term": {
"sessionid": "55622"
}
}
]
}
}
}
}'

how can I implement the above with this kind of call?
SearchResponse response = client.prepareSearch("sessionmsg")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(QueryBuilders.termQuery("roomid", "7087"))
.setFrom(0).setSize(60).setExplain(true).execute().actionGet();

On Tuesday, March 24, 2015 at 8:05:57 AM UTC-4, David Pilato wrote:

Did you look at answer branch?

Answers are on answers branch:

GitHub - elasticsearchfr/hands-on at answers

David

Le 24 mars 2015 à 12:58, 'newbo' via elasticsearch <
elasti...@googlegroups.com <javascript:>> a écrit :

Hey David,

I'm looking at the code now and I see lots of TODOs and nulls, but no
actual indexing. Perhaps that code needs to be cleaned up?

On Thursday, November 15, 2012 at 9:11:02 AM UTC-5, David Pilato wrote:

Hi Ryan,

Have a look at this: GitHub - elasticsearchfr/hands-on: Hands On Lab
Answers are on answers branch:
GitHub - elasticsearchfr/hands-on at answers

Some slides (in french but you can understand code) are here:
Hands on lab Elasticsearch | PPT

I'm waiting for ES team to merge my Java tutorial:
https://github.com/elasticsearch/elasticsearch.github.com/pull/321
It will look like this:
https://github.com/dadoonet/elasticsearch.github.com/blob/9f6dae922247a81f1c72c77769d1dce3ad09dca5/tutorials/_posts/2012-11-07-using-java-api-basics.markdown

HTH

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

--
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 elasticsearc...@googlegroups.com <javascript:>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/92c7a0f5-ef47-45c2-b121-8c0302fa8c71%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/92c7a0f5-ef47-45c2-b121-8c0302fa8c71%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/6541b592-3e0f-4d6e-8ae3-6e37595d3ee2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Here is how you do it..

QueryBuilder qb = QueryBuilders
.boolQuery()
.must(QueryBuilders.termQuery("roomid","7087") )
.must(QueryBuilders.termQuery("sessionid","55622"));

On Wednesday, November 14, 2012 at 10:04:41 PM UTC-5, Ryan Compton wrote:

I am completely new to Elastic Search. I have figured out enough that I
can retrieve jsons from our cluster with:

-bash-3.2$ curl -XGET http://10.10.1.7:9200/twitter-sept/_search -d
'{"query":{"bool":{"must":[{"term":{"tweet":"elastic"}}],"must_not":,"should":}},"from":0,"size":50,"sort":,"facets":{}}'

Since most of my code is in Java I figured things would be easier if I
used the Java API. I am completely stumped on how to do it. The guide
Elasticsearch Platform — Find real-time answers at scale | Elastic is
confusing. What are all those classes? Where are the javadocs? Is there a
simple example somewhere that explains how I can reproduce the above
command in Java? Do I need a TransportClient, a SearchSourceBuilder,
ImmutableSettings?

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/84c0ad1c-7242-49ae-ac2b-3f9ea0d0a619%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.