Translate REST call to Java API

Hi,

I'm having a hard time converting a REST call to the JAVA equivalent,
the exact REST call is:

curl -XGET http://192.168.0.100:9200/inventory/_search?pretty=true -d
'
{
"query" : {
"query_string" : {
"fields" : ["part_number", "category",
"description"],
"query" : "Ac Adapter"
}
}

}
'

but I would really love to "learn" how to do it myself.

Thanks

Diego

First you need the querybuilder:

QueryStringQueryBuilder qsqb = QueryBuilders.queryString("Ac
Adapter").field("part_number", 1).field("category",
1).field("description", 1);

Then you need to set the query:
SearchRequestBuilder srb =
client.prepareSearch("inventory").setQuery(qsqb);

Now you can add facets or set the filter:
srb.addFacet();srb.setFilter();

As a last step you need to execute the query and fetch it / or add a
listener to it ...
srb.execute().actionGet();srb.execute().addListener();

Regards,
Peter.

On 4 Nov., 05:25, fmpwizard fmpwiz...@gmail.com wrote:

Hi,

I'm having a hard time converting a REST call to the JAVA equivalent,
the exact REST call is:

curl -XGEThttp://192.168.0.100:9200/inventory/_search?pretty=true-d
'
{
"query" : {
"query_string" : {
"fields" : ["part_number", "category",
"description"],
"query" : "Ac Adapter"
}
}

}

'

but I would really love to "learn" how to do it myself.

Thanks

Diego

works great, thank you very much!

Diego

On Fri, Nov 4, 2011 at 4:50 AM, Karussell tableyourtime@googlemail.com wrote:

First you need the querybuilder:

QueryStringQueryBuilder qsqb = QueryBuilders.queryString("Ac
Adapter").field("part_number", 1).field("category",
1).field("description", 1);

Then you need to set the query:
SearchRequestBuilder srb =
client.prepareSearch("inventory").setQuery(qsqb);

Now you can add facets or set the filter:
srb.addFacet();srb.setFilter();

As a last step you need to execute the query and fetch it / or add a
listener to it ...
srb.execute().actionGet();srb.execute().addListener();

Regards,
Peter.

On 4 Nov., 05:25, fmpwizard fmpwiz...@gmail.com wrote:

Hi,

I'm having a hard time converting a REST call to the JAVA equivalent,
the exact REST call is:

curl -XGEThttp://192.168.0.100:9200/inventory/_search?pretty=true-d
'
{
"query" : {
"query_string" : {
"fields" : ["part_number", "category",
"description"],
"query" : "Ac Adapter"
}
}

}

'

but I would really love to "learn" how to do it myself.

Thanks

Diego

--
Diego Medina
Web Developer
diego@fmpwizard.com
http://www.fmpwizard.com

Hi All,

How to search specific text using elastic search 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..

how to get records..

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.

On Monday, March 11, 2013 12:07:59 PM UTC+5:30, 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.

When starting a new discussion on a mailing list, please do not reply to
an existing message, instead start a fresh email. Even if you change the
subject line of your email, other mail headers still track which thread
you replied to and your question is "hidden" in that thread and gets less
attention. It makes following discussions in the mailing list archives
particularly difficult

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