# How to search text using java elastic search

**URL:** <https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092>\
**Category:** Elasticsearch\
**Created:** [March 11, 2013, 9:19am UTC](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092 "2013-03-11T09:19:20Z")\
**Posts on this page:** 20\
**Page:** 1

<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, 9:19am UTC](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092/1 "2013-03-11T09:19:20Z")

</div>

Hi All,

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](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, 9:37am UTC](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092/2 "2013-03-11T09:37:29Z")

</div>

hey there,

can you talk through REST to your ES cluster, if so can you paste the  
request and the response? I am kind of confused to see some discovery  
settings in you client setup, can you try removing all these settings for  
now?  
Anyway, you are using termQuery which is not analyzed or processed, this is  
likely not what you want, can you try matchQuery instead?

simon

On Monday, March 11, 2013 10:19:20 AM UTC+1, srikanth gone wrote:

> Hi All,
> 
> 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](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:** ![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, 10:31am UTC](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092/3 "2013-03-11T10:31:18Z")

</div>

this is my code..

Node node = null;  
node = NodeBuilder.nodeBuilder().node();

```
    Client client = node.client();
    SearchRequestBuilder searchRequestBuilder = 

```

client.prepareSearch("\_river");  
searchRequestBuilder.setTypes("dc\_user\_river");  
searchRequestBuilder.setSearchType(SearchType.QUERY\_AND\_FETCH);  
searchRequestBuilder.setQuery(QueryBuilders.fuzzyQuery("userName",  
"SampleUser"));  
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" : 235,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 1,  
"successful" : 1,  
"failed" : 0  
},  
"hits" : {  
"total" : 0,  
"max\_score" : null,  
"hits" : []  
}  
}

i am not able to use the QueryBuilders.matchQuery() method.. is there any  
jars required.?

--  
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, 11:48am UTC](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092/4 "2013-03-11T11:48:53Z")

</div>

hey,

does you index exists at all? can you provide some more infos?  
you don't need any additional jars for match queyr, which version are you  
using?  
simon

On Monday, March 11, 2013 11:31:18 AM UTC+1, srikanth gone wrote:

> this is my code..
> 
> Node node = null;  
> node = NodeBuilder.nodeBuilder().node();
> 
> ```
> Client client = node.client();
> SearchRequestBuilder searchRequestBuilder = 
> 
> ```
> 
> client.prepareSearch("\_river");  
> searchRequestBuilder.setTypes("dc\_user\_river");  
> searchRequestBuilder.setSearchType(SearchType.QUERY\_AND\_FETCH);  
> searchRequestBuilder.setQuery(QueryBuilders.fuzzyQuery("userName",  
> "SampleUser"));  
> 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" : 235,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 1,  
> "successful" : 1,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 0,  
> "max\_score" : null,  
> "hits" :   
> }  
> }
> 
> i am not able to use the QueryBuilders.matchQuery() method.. is there any  
> jars required.?

--  
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:** ![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, 11:58am UTC](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092/5 "2013-03-11T11:58:44Z")

</div>

elastic server version is 0.19.8  
On Monday, March 11, 2013 5:18:53 PM UTC+5:30, simonw wrote:

> hey,
> 
> does you index exists at all? can you provide some more infos?  
> you don't need any additional jars for match queyr, which version are you  
> using?  
> simon
> 
> On Monday, March 11, 2013 11:31:18 AM UTC+1, srikanth gone wrote:
> 
> > this is my code..
> > 
> > Node node = null;  
> > node = NodeBuilder.nodeBuilder().node();
> > 
> > ```
> > Client client = node.client();
> > SearchRequestBuilder searchRequestBuilder = 
> > 
> > ```
> > 
> > client.prepareSearch("\_river");  
> > searchRequestBuilder.setTypes("dc\_user\_river");  
> > searchRequestBuilder.setSearchType(SearchType.QUERY\_AND\_FETCH);
> > 
> > searchRequestBuilder.setQuery(QueryBuilders.fuzzyQuery("userName",  
> > "SampleUser"));  
> > 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" : 235,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 1,  
> > "successful" : 1,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 0,  
> > "max\_score" : null,  
> > "hits" :   
> > }  
> > }
> > 
> > i am not able to use the QueryBuilders.matchQuery() method.. is there  
> > any jars required.?

--  
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, 12:04pm UTC](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092/6 "2013-03-11T12:04:53Z")

</div>

On Monday, March 11, 2013 12:58:44 PM UTC+1, srikanth gone wrote:

> elastic server version is 0.19.8

then use textQuery

but answer all my other qeustions before please

simon

> On Monday, March 11, 2013 5:18:53 PM UTC+5:30, simonw wrote:
> 
> > hey,
> > 
> > does you index exists at all? can you provide some more infos?  
> > you don't need any additional jars for match queyr, which version are you  
> > using?  
> > simon
> > 
> > On Monday, March 11, 2013 11:31:18 AM UTC+1, srikanth gone wrote:
> > 
> > > this is my code..
> > > 
> > > Node node = null;  
> > > node = NodeBuilder.nodeBuilder().node();
> > > 
> > > ```
> > > Client client = node.client();
> > > SearchRequestBuilder searchRequestBuilder = 
> > > 
> > > ```
> > > 
> > > client.prepareSearch("\_river");  
> > > searchRequestBuilder.setTypes("dc\_user\_river");  
> > > searchRequestBuilder.setSearchType(SearchType.QUERY\_AND\_FETCH);
> > > 
> > > searchRequestBuilder.setQuery(QueryBuilders.fuzzyQuery("userName",  
> > > "SampleUser"));  
> > > 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" : 235,  
> > > "timed\_out" : false,  
> > > "\_shards" : {  
> > > "total" : 1,  
> > > "successful" : 1,  
> > > "failed" : 0  
> > > },  
> > > "hits" : {  
> > > "total" : 0,  
> > > "max\_score" : null,  
> > > "hits" :   
> > > }  
> > > }
> > > 
> > > i am not able to use the QueryBuilders.matchQuery() method.. is there  
> > > any jars required.?

--  
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:** ![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, 12:27pm UTC](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092/7 "2013-03-11T12:27:39Z")

</div>

hi simonw,  
ya. actually i have created indexes using curl.. like this..

curl -XPUT "[http://localhost:9200/\_river/dc\_role\_river/\_meta](http://localhost:9200/_river/dc_role_river/_meta)" -d {  
"type": "mongodb",  
"mongodb": {  
"db": "data-collection",  
"collection": "DC\_USER"  
},  
"index": {  
"name": "dc\_user\_idx",  
"type": "DC\_USER"  
}  
}

is there any mapping missed..

On Monday, March 11, 2013 5:34:53 PM UTC+5:30, simonw wrote:

> On Monday, March 11, 2013 12:58:44 PM UTC+1, srikanth gone wrote:
> 
> > elastic server version is 0.19.8
> 
> then use textQuery
> 
> but answer all my other qeustions before please
> 
> simon
> 
> > On Monday, March 11, 2013 5:18:53 PM UTC+5:30, simonw wrote:
> > 
> > > hey,
> > > 
> > > does you index exists at all? can you provide some more infos?  
> > > you don't need any additional jars for match queyr, which version are  
> > > you using?  
> > > simon
> > > 
> > > On Monday, March 11, 2013 11:31:18 AM UTC+1, srikanth gone wrote:
> > > 
> > > > this is my code..
> > > > 
> > > > Node node = null;  
> > > > node = NodeBuilder.nodeBuilder().node();
> > > > 
> > > > ```
> > > > Client client = node.client();
> > > > SearchRequestBuilder searchRequestBuilder = 
> > > > 
> > > > ```
> > > > 
> > > > client.prepareSearch("\_river");  
> > > > searchRequestBuilder.setTypes("dc\_user\_river");  
> > > > searchRequestBuilder.setSearchType(SearchType.QUERY\_AND\_FETCH);
> > > > 
> > > > searchRequestBuilder.setQuery(QueryBuilders.fuzzyQuery("userName",  
> > > > "SampleUser"));  
> > > > 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" : 235,  
> > > > "timed\_out" : false,  
> > > > "\_shards" : {  
> > > > "total" : 1,  
> > > > "successful" : 1,  
> > > > "failed" : 0  
> > > > },  
> > > > "hits" : {  
> > > > "total" : 0,  
> > > > "max\_score" : null,  
> > > > "hits" :   
> > > > }  
> > > > }
> > > > 
> > > > i am not able to use the QueryBuilders.matchQuery() method.. is there  
> > > > any jars required.?

--  
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:** ![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, 12:32pm UTC](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092/8 "2013-03-11T12:32:43Z")

</div>

actually i am using mongodb as database. how to create indexs for tables  
at a time.

is there any api is there in java..

On Monday, March 11, 2013 5:57:39 PM UTC+5:30, srikanth gone wrote:

> hi simonw,  
> ya. actually i have created indexes using curl.. like this..
> 
> curl -XPUT "[http://localhost:9200/\_river/dc\_role\_river/\_meta](http://localhost:9200/_river/dc_role_river/_meta)" -d {  
> "type": "mongodb",  
> "mongodb": {  
> "db": "data-collection",  
> "collection": "DC\_USER"  
> },  
> "index": {  
> "name": "dc\_user\_idx",  
> "type": "DC\_USER"  
> }  
> }
> 
> is there any mapping missed..
> 
> On Monday, March 11, 2013 5:34:53 PM UTC+5:30, simonw wrote:
> 
> > On Monday, March 11, 2013 12:58:44 PM UTC+1, srikanth gone wrote:
> > 
> > > elastic server version is 0.19.8
> > 
> > then use textQuery
> > 
> > but answer all my other qeustions before please
> > 
> > simon
> > 
> > > On Monday, March 11, 2013 5:18:53 PM UTC+5:30, simonw wrote:
> > > 
> > > > hey,
> > > > 
> > > > does you index exists at all? can you provide some more infos?  
> > > > you don't need any additional jars for match queyr, which version are  
> > > > you using?  
> > > > simon
> > > > 
> > > > On Monday, March 11, 2013 11:31:18 AM UTC+1, srikanth gone wrote:
> > > > 
> > > > > this is my code..
> > > > > 
> > > > > Node node = null;  
> > > > > node = NodeBuilder.nodeBuilder().node();
> > > > > 
> > > > > ```
> > > > > Client client = node.client();
> > > > > SearchRequestBuilder searchRequestBuilder = 
> > > > > 
> > > > > ```
> > > > > 
> > > > > client.prepareSearch("\_river");  
> > > > > searchRequestBuilder.setTypes("dc\_user\_river");  
> > > > > searchRequestBuilder.setSearchType(SearchType.QUERY\_AND\_FETCH);
> > > > > 
> > > > > searchRequestBuilder.setQuery(QueryBuilders.fuzzyQuery("userName",  
> > > > > "SampleUser"));  
> > > > > 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" : 235,  
> > > > > "timed\_out" : false,  
> > > > > "\_shards" : {  
> > > > > "total" : 1,  
> > > > > "successful" : 1,  
> > > > > "failed" : 0  
> > > > > },  
> > > > > "hits" : {  
> > > > > "total" : 0,  
> > > > > "max\_score" : null,  
> > > > > "hits" :   
> > > > > }  
> > > > > }
> > > > > 
> > > > > i am not able to use the QueryBuilders.matchQuery() method.. is there  
> > > > > any jars required.?

--  
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:** ![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, 12:59pm UTC](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092/9 "2013-03-11T12:59:22Z")

</div>

hi simonw,

if i use this code..

SearchResponse response = client.prepareSearch().execute().actionGet();

System.out.println(response);  
SearchHit results = response.getHits().getHits();  
System.out.println(results);  
for (SearchHit hit : results) {  
System.out.println(hit.getId()); //prints out the id of the  
document  
result = hit.getSource(); //the retrieved document  
}

i am getting this output.

{  
"took" : 63,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 91,  
"successful" : 91,  
"failed" : 0  
},  
"hits" : {  
"total" : 122,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "\_river",  
"\_type" : "dc\_demo\_group\_river",  
"\_id" : "data-collection.DC\_DEMO\_GROUP",  
"\_score" : 1.0, "\_source" : {"mongodb":{"\_last\_ts":"{ "$ts" :  
1362465631 , "$inc" : 1}"}}  
}, {  
"\_index" : "\_river",  
"\_type" : "dc\_provider\_river",  
"\_id" : "\_meta",  
"\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
{ "db": "data-collection", "collection": "DC\_PROVIDER"  
}, "index": { "name": "dc\_provider\_idx", "type":  
"DC\_PROVIDER" }}  
}, {  
"\_index" : "\_river",  
"\_type" : "dc\_practice\_river",  
"\_id" : "\_meta",  
"\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
{ "db": "data-collection", "collection": "DC\_PRACTICE"  
}, "index": { "name": "dc\_practice\_idx", "type":  
"DC\_PRACTICE" }}  
}, {  
"\_index" : "\_river",  
"\_type" : "dc\_patient\_topic\_river",  
"\_id" : "\_meta",  
"\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
{ "db": "data-collection", "collection":  
"DC\_PATIENT\_TOPIC\_DATA" }, "index": { "name":  
"dc\_patient\_topic\_data\_idx", "type": "DC\_PATIENT\_TOPIC\_DATA" }}  
}, {  
"\_index" : "\_river",  
"\_type" : "dc\_patient\_river",  
"\_id" : "\_meta",  
"\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
{ "db": "data-collection", "collection": "DC\_PATIENT"  
}, "index": { "name": "dc\_patient\_idx", "type":  
"DC\_PATIENT" }}  
}, {  
"\_index" : "\_river",  
"\_type" : "dc\_demo\_jursidiction\_river",  
"\_id" : "data-collection.DC\_DEMO\_JURISDICTION",  
"\_score" : 1.0, "\_source" : {"mongodb":{"\_last\_ts":"{ "$ts" :  
1362465631 , "$inc" : 1}"}}  
}, {  
"\_index" : "\_river",  
"\_type" : "dc\_demo\_rule\_metadata\_river",  
"\_id" : "\_meta",  
"\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
{ "db": "data-collection", "collection":  
"DC\_RULES\_METADATA" }, "index": { "name":  
"dc\_rule\_metadata\_idx", "type": "DC\_RULES\_METADATA" }}  
}, {  
"\_index" : "\_river",  
"\_type" : "dc\_role\_river",  
"\_id" : "\_meta",  
"\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
{ "db": "data-collection", "collection": "DC\_ROLE" },  
"index": { "name": "dc\_role\_idx", "type": "DC\_ROLE" }}  
}, {  
"\_index" : "\_river",  
"\_type" : "dc\_demo\_group\_river",  
"\_id" : "\_meta",  
"\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
{ "db": "data-collection", "collection": "DC\_DEMO\_GROUP"  
}, "index": { "name": "dc\_demo\_group\_idx", "type":  
"DC\_DEMO\_GROUP" }}  
}, {  
"\_index" : "\_river",  
"\_type" : "dc\_topic\_river",  
"\_id" : "\_meta",  
"\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
{ "db": "data-collection", "collection": "DC\_TOPIC" },  
"index": { "name": "dc\_topic\_idx", "type": "DC\_TOPIC" }}  
} ]  
}  
}

> > > > >

--  
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, 1:04pm UTC](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092/10 "2013-03-11T13:04:34Z")

</div>

ok so are you sure you have a 'dc\_user\_river' type?

what happens if your remove the query entirely and just filter by the  
'dc\_user\_river' type?

simon

On Monday, March 11, 2013 1:59:22 PM UTC+1, srikanth gone wrote:

> hi simonw,
> 
> if i use this code..
> 
> SearchResponse response = client.prepareSearch().execute().actionGet();
> 
> System.out.println(response);  
> SearchHit results = response.getHits().getHits();  
> System.out.println(results);  
> for (SearchHit hit : results) {  
> System.out.println(hit.getId()); //prints out the id of the  
> document  
> result = hit.getSource(); //the retrieved document  
> }
> 
> i am getting this output.
> 
> {  
> "took" : 63,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 91,  
> "successful" : 91,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 122,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "\_river",  
> "\_type" : "dc\_demo\_group\_river",  
> "\_id" : "data-collection.DC\_DEMO\_GROUP",  
> "\_score" : 1.0, "\_source" : {"mongodb":{"\_last\_ts":"{ "$ts" :  
> 1362465631 , "$inc" : 1}"}}  
> }, {  
> "\_index" : "\_river",  
> "\_type" : "dc\_provider\_river",  
> "\_id" : "\_meta",  
> "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
> { "db": "data-collection", "collection": "DC\_PROVIDER"  
> }, "index": { "name": "dc\_provider\_idx", "type":  
> "DC\_PROVIDER" }}  
> }, {  
> "\_index" : "\_river",  
> "\_type" : "dc\_practice\_river",  
> "\_id" : "\_meta",  
> "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
> { "db": "data-collection", "collection": "DC\_PRACTICE"  
> }, "index": { "name": "dc\_practice\_idx", "type":  
> "DC\_PRACTICE" }}  
> }, {  
> "\_index" : "\_river",  
> "\_type" : "dc\_patient\_topic\_river",  
> "\_id" : "\_meta",  
> "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
> { "db": "data-collection", "collection":  
> "DC\_PATIENT\_TOPIC\_DATA" }, "index": { "name":  
> "dc\_patient\_topic\_data\_idx", "type": "DC\_PATIENT\_TOPIC\_DATA" }}  
> }, {  
> "\_index" : "\_river",  
> "\_type" : "dc\_patient\_river",  
> "\_id" : "\_meta",  
> "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
> { "db": "data-collection", "collection": "DC\_PATIENT"  
> }, "index": { "name": "dc\_patient\_idx", "type":  
> "DC\_PATIENT" }}  
> }, {  
> "\_index" : "\_river",  
> "\_type" : "dc\_demo\_jursidiction\_river",  
> "\_id" : "data-collection.DC\_DEMO\_JURISDICTION",  
> "\_score" : 1.0, "\_source" : {"mongodb":{"\_last\_ts":"{ "$ts" :  
> 1362465631 , "$inc" : 1}"}}  
> }, {  
> "\_index" : "\_river",  
> "\_type" : "dc\_demo\_rule\_metadata\_river",  
> "\_id" : "\_meta",  
> "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
> { "db": "data-collection", "collection":  
> "DC\_RULES\_METADATA" }, "index": { "name":  
> "dc\_rule\_metadata\_idx", "type": "DC\_RULES\_METADATA" }}  
> }, {  
> "\_index" : "\_river",  
> "\_type" : "dc\_role\_river",  
> "\_id" : "\_meta",  
> "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
> { "db": "data-collection", "collection": "DC\_ROLE" },  
> "index": { "name": "dc\_role\_idx", "type": "DC\_ROLE" }}  
> }, {  
> "\_index" : "\_river",  
> "\_type" : "dc\_demo\_group\_river",  
> "\_id" : "\_meta",  
> "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
> { "db": "data-collection", "collection": "DC\_DEMO\_GROUP"  
> }, "index": { "name": "dc\_demo\_group\_idx", "type":  
> "DC\_DEMO\_GROUP" }}  
> }, {  
> "\_index" : "\_river",  
> "\_type" : "dc\_topic\_river",  
> "\_id" : "\_meta",  
> "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
> { "db": "data-collection", "collection": "DC\_TOPIC" },  
> "index": { "name": "dc\_topic\_idx", "type": "DC\_TOPIC" }}  
> } ]  
> }  
> }
> 
> > > > > >

--  
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:** ![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, 1:50pm UTC](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092/11 "2013-03-11T13:50:18Z")

</div>

i did like this..

SearchResponse response =  
client.prepareSearch().setIndices("\_river").setTypes("dc\_user\_river").execute().actionGet();

output is  
{  
"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" : "\_meta",  
"\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
{ "db": "data-collection", "collection": "DC\_USER" },  
"index": { "name": "dc\_user\_idx", "type": "DC\_USER" }}  
}, {  
"\_index" : "\_river",  
"\_type" : "dc\_user\_river",  
"\_id" : "\_status",  
"\_score" : 1.0, "\_source" :  
{"ok":true,"node":{"id":"Snvd2nvCQB-4hpKUvMQtqA","name":"Jaeger","transport\_address":"inet[/192.168.10.2:9300]"}}  
} ]  
}  
}

On Monday, March 11, 2013 6:34:34 PM UTC+5:30, simonw wrote:

> ok so are you sure you have a 'dc\_user\_river' type?
> 
> what happens if your remove the query entirely and just filter by the  
> 'dc\_user\_river' type?
> 
> simon
> 
> On Monday, March 11, 2013 1:59:22 PM UTC+1, srikanth gone wrote:
> 
> > hi simonw,
> > 
> > if i use this code..
> > 
> > SearchResponse response = client.prepareSearch().execute().actionGet();
> > 
> > System.out.println(response);  
> > SearchHit results = response.getHits().getHits();  
> > System.out.println(results);  
> > for (SearchHit hit : results) {  
> > System.out.println(hit.getId()); //prints out the id of the  
> > document  
> > result = hit.getSource(); //the retrieved document  
> > }
> > 
> > i am getting this output.
> > 
> > {  
> > "took" : 63,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 91,  
> > "successful" : 91,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 122,  
> > "max\_score" : 1.0,  
> > "hits" : [ {  
> > "\_index" : "\_river",  
> > "\_type" : "dc\_demo\_group\_river",  
> > "\_id" : "data-collection.DC\_DEMO\_GROUP",  
> > "\_score" : 1.0, "\_source" : {"mongodb":{"\_last\_ts":"{ "$ts" :  
> > 1362465631 , "$inc" : 1}"}}  
> > }, {  
> > "\_index" : "\_river",  
> > "\_type" : "dc\_provider\_river",  
> > "\_id" : "\_meta",  
> > "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
> > { "db": "data-collection", "collection": "DC\_PROVIDER"  
> > }, "index": { "name": "dc\_provider\_idx", "type":  
> > "DC\_PROVIDER" }}  
> > }, {  
> > "\_index" : "\_river",  
> > "\_type" : "dc\_practice\_river",  
> > "\_id" : "\_meta",  
> > "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
> > { "db": "data-collection", "collection": "DC\_PRACTICE"  
> > }, "index": { "name": "dc\_practice\_idx", "type":  
> > "DC\_PRACTICE" }}  
> > }, {  
> > "\_index" : "\_river",  
> > "\_type" : "dc\_patient\_topic\_river",  
> > "\_id" : "\_meta",  
> > "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
> > { "db": "data-collection", "collection":  
> > "DC\_PATIENT\_TOPIC\_DATA" }, "index": { "name":  
> > "dc\_patient\_topic\_data\_idx", "type": "DC\_PATIENT\_TOPIC\_DATA" }}  
> > }, {  
> > "\_index" : "\_river",  
> > "\_type" : "dc\_patient\_river",  
> > "\_id" : "\_meta",  
> > "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
> > { "db": "data-collection", "collection": "DC\_PATIENT"  
> > }, "index": { "name": "dc\_patient\_idx", "type":  
> > "DC\_PATIENT" }}  
> > }, {  
> > "\_index" : "\_river",  
> > "\_type" : "dc\_demo\_jursidiction\_river",  
> > "\_id" : "data-collection.DC\_DEMO\_JURISDICTION",  
> > "\_score" : 1.0, "\_source" : {"mongodb":{"\_last\_ts":"{ "$ts" :  
> > 1362465631 , "$inc" : 1}"}}  
> > }, {  
> > "\_index" : "\_river",  
> > "\_type" : "dc\_demo\_rule\_metadata\_river",  
> > "\_id" : "\_meta",  
> > "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
> > { "db": "data-collection", "collection":  
> > "DC\_RULES\_METADATA" }, "index": { "name":  
> > "dc\_rule\_metadata\_idx", "type": "DC\_RULES\_METADATA" }}  
> > }, {  
> > "\_index" : "\_river",  
> > "\_type" : "dc\_role\_river",  
> > "\_id" : "\_meta",  
> > "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
> > { "db": "data-collection", "collection": "DC\_ROLE" },  
> > "index": { "name": "dc\_role\_idx", "type": "DC\_ROLE" }}  
> > }, {  
> > "\_index" : "\_river",  
> > "\_type" : "dc\_demo\_group\_river",  
> > "\_id" : "\_meta",  
> > "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
> > { "db": "data-collection", "collection": "DC\_DEMO\_GROUP"  
> > }, "index": { "name": "dc\_demo\_group\_idx", "type":  
> > "DC\_DEMO\_GROUP" }}  
> > }, {  
> > "\_index" : "\_river",  
> > "\_type" : "dc\_topic\_river",  
> > "\_id" : "\_meta",  
> > "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
> > { "db": "data-collection", "collection": "DC\_TOPIC" },  
> > "index": { "name": "dc\_topic\_idx", "type": "DC\_TOPIC" }}  
> > } ]  
> > }  
> > }
> > 
> > > > > > >

--  
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:** ![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:** [March 11, 2013, 1:53pm UTC](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092/12 "2013-03-11T13:53:48Z")

</div>

Hi,

Just jumping in this thread.

What are you trying to achieve?  
Do you want to access to the river to to documents indexed by the river?

Can you describe a little bit what you are trying to do?  
Also, have a look at: [http://www.elasticsearch.org/guide/reference/java-api/](http://www.elasticsearch.org/guide/reference/java-api/)  
And [GitHub - elasticsearchfr/hands-on at answers](https://github.com/elasticsearchfr/hands-on/tree/answers)

To have some information on how to build requests using Java API.

Hope this help.

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 11 mars 2013 à 14:50, srikanth gone [srikanthg93@gmail.com](mailto:srikanthg93@gmail.com) a écrit :

> i did like this..
> 
> SearchResponse response = client.prepareSearch().setIndices("\_river").setTypes("dc\_user\_river").execute().actionGet();
> 
> output is  
> {  
> "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" : "\_meta",  
> "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb": { "db": "data-collection", "collection": "DC\_USER" }, "index": { "name": "dc\_user\_idx", "type": "DC\_USER" }}  
> }, {  
> "\_index" : "\_river",  
> "\_type" : "dc\_user\_river",  
> "\_id" : "\_status",  
> "\_score" : 1.0, "\_source" : {"ok":true,"node":{"id":"Snvd2nvCQB-4hpKUvMQtqA","name":"Jaeger","transport\_address":"inet[/192.168.10.2:9300]"}}  
> } ]  
> }  
> }
> 
> On Monday, March 11, 2013 6:34:34 PM UTC+5:30, simonw wrote:  
> ok so are you sure you have a 'dc\_user\_river' type?
> 
> what happens if your remove the query entirely and just filter by the 'dc\_user\_river' type?
> 
> simon
> 
> On Monday, March 11, 2013 1:59:22 PM UTC+1, srikanth gone wrote:
> 
> hi simonw,
> 
> if i use this code..
> 
> SearchResponse response = client.prepareSearch().execute().actionGet();
> 
> System.out.println(response);  
> SearchHit results = response.getHits().getHits();  
> System.out.println(results);  
> for (SearchHit hit : results) {  
> System.out.println(hit.getId()); //prints out the id of the document  
> result = hit.getSource(); //the retrieved document  
> }
> 
> i am getting this output.
> 
> {  
> "took" : 63,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 91,  
> "successful" : 91,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 122,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "\_river",  
> "\_type" : "dc\_demo\_group\_river",  
> "\_id" : "data-collection.DC\_DEMO\_GROUP",  
> "\_score" : 1.0, "\_source" : {"mongodb":{"\_last\_ts":"{ "$ts" : 1362465631 , "$inc" : 1}"}}  
> }, {  
> "\_index" : "\_river",  
> "\_type" : "dc\_provider\_river",  
> "\_id" : "\_meta",  
> "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb": { "db": "data-collection", "collection": "DC\_PROVIDER" }, "index": { "name": "dc\_provider\_idx", "type": "DC\_PROVIDER" }}  
> }, {  
> "\_index" : "\_river",  
> "\_type" : "dc\_practice\_river",  
> "\_id" : "\_meta",  
> "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb": { "db": "data-collection", "collection": "DC\_PRACTICE" }, "index": { "name": "dc\_practice\_idx", "type": "DC\_PRACTICE" }}  
> }, {  
> "\_index" : "\_river",  
> "\_type" : "dc\_patient\_topic\_river",  
> "\_id" : "\_meta",  
> "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb": { "db": "data-collection", "collection": "DC\_PATIENT\_TOPIC\_DATA" }, "index": { "name": "dc\_patient\_topic\_data\_idx", "type": "DC\_PATIENT\_TOPIC\_DATA" }}  
> }, {  
> "\_index" : "\_river",  
> "\_type" : "dc\_patient\_river",  
> "\_id" : "\_meta",  
> "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb": { "db": "data-collection", "collection": "DC\_PATIENT" }, "index": { "name": "dc\_patient\_idx", "type": "DC\_PATIENT" }}  
> }, {  
> "\_index" : "\_river",  
> "\_type" : "dc\_demo\_jursidiction\_river",  
> "\_id" : "data-collection.DC\_DEMO\_JURISDICTION",  
> "\_score" : 1.0, "\_source" : {"mongodb":{"\_last\_ts":"{ "$ts" : 1362465631 , "$inc" : 1}"}}  
> }, {  
> "\_index" : "\_river",  
> "\_type" : "dc\_demo\_rule\_metadata\_river",  
> "\_id" : "\_meta",  
> "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb": { "db": "data-collection", "collection": "DC\_RULES\_METADATA" }, "index": { "name": "dc\_rule\_metadata\_idx", "type": "DC\_RULES\_METADATA" }}  
> }, {  
> "\_index" : "\_river",  
> "\_type" : "dc\_role\_river",  
> "\_id" : "\_meta",  
> "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb": { "db": "data-collection", "collection": "DC\_ROLE" }, "index": { "name": "dc\_role\_idx", "type": "DC\_ROLE" }}  
> }, {  
> "\_index" : "\_river",  
> "\_type" : "dc\_demo\_group\_river",  
> "\_id" : "\_meta",  
> "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb": { "db": "data-collection", "collection": "DC\_DEMO\_GROUP" }, "index": { "name": "dc\_demo\_group\_idx", "type": "DC\_DEMO\_GROUP" }}  
> }, {  
> "\_index" : "\_river",  
> "\_type" : "dc\_topic\_river",  
> "\_id" : "\_meta",  
> "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb": { "db": "data-collection", "collection": "DC\_TOPIC" }, "index": { "name": "dc\_topic\_idx", "type": "DC\_TOPIC" }}  
> } ]  
> }  
> }
> 
> --  
> 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).

--  
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:** ![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:** [March 11, 2013, 1:54pm UTC](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092/13 "2013-03-11T13:54:54Z")

</div>

Sorry.

Replace  
Do you want to access to the river to to documents indexed by the river?

By  
Do you want to access to the river OR to documents indexed by the river?

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 11 mars 2013 à 14:53, David Pilato [david@pilato.fr](mailto:david@pilato.fr) a écrit :

> Hi,
> 
> Just jumping in this thread.
> 
> What are you trying to achieve?  
> Do you want to access to the river to to documents indexed by the river?
> 
> Can you describe a little bit what you are trying to do?  
> Also, have a look at: [http://www.elasticsearch.org/guide/reference/java-api/](http://www.elasticsearch.org/guide/reference/java-api/)  
> And [GitHub - elasticsearchfr/hands-on at answers](https://github.com/elasticsearchfr/hands-on/tree/answers)
> 
> To have some information on how to build requests using Java API.
> 
> Hope this help.
> 
> --  
> David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
> @dadoonet | @elasticsearchfr | @scrutmydocs
> 
> Le 11 mars 2013 à 14:50, srikanth gone [srikanthg93@gmail.com](mailto:srikanthg93@gmail.com) a écrit :
> 
> > i did like this..
> > 
> > SearchResponse response = client.prepareSearch().setIndices("\_river").setTypes("dc\_user\_river").execute().actionGet();
> > 
> > output is  
> > {  
> > "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" : "\_meta",  
> > "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb": { "db": "data-collection", "collection": "DC\_USER" }, "index": { "name": "dc\_user\_idx", "type": "DC\_USER" }}  
> > }, {  
> > "\_index" : "\_river",  
> > "\_type" : "dc\_user\_river",  
> > "\_id" : "\_status",  
> > "\_score" : 1.0, "\_source" : {"ok":true,"node":{"id":"Snvd2nvCQB-4hpKUvMQtqA","name":"Jaeger","transport\_address":"inet[/192.168.10.2:9300]"}}  
> > } ]  
> > }  
> > }
> > 
> > On Monday, March 11, 2013 6:34:34 PM UTC+5:30, simonw wrote:  
> > ok so are you sure you have a 'dc\_user\_river' type?
> > 
> > what happens if your remove the query entirely and just filter by the 'dc\_user\_river' type?
> > 
> > simon
> > 
> > On Monday, March 11, 2013 1:59:22 PM UTC+1, srikanth gone wrote:
> > 
> > hi simonw,
> > 
> > if i use this code..
> > 
> > SearchResponse response = client.prepareSearch().execute().actionGet();
> > 
> > System.out.println(response);  
> > SearchHit results = response.getHits().getHits();  
> > System.out.println(results);  
> > for (SearchHit hit : results) {  
> > System.out.println(hit.getId()); //prints out the id of the document  
> > result = hit.getSource(); //the retrieved document  
> > }
> > 
> > i am getting this output.
> > 
> > {  
> > "took" : 63,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 91,  
> > "successful" : 91,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 122,  
> > "max\_score" : 1.0,  
> > "hits" : [ {  
> > "\_index" : "\_river",  
> > "\_type" : "dc\_demo\_group\_river",  
> > "\_id" : "data-collection.DC\_DEMO\_GROUP",  
> > "\_score" : 1.0, "\_source" : {"mongodb":{"\_last\_ts":"{ "$ts" : 1362465631 , "$inc" : 1}"}}  
> > }, {  
> > "\_index" : "\_river",  
> > "\_type" : "dc\_provider\_river",  
> > "\_id" : "\_meta",  
> > "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb": { "db": "data-collection", "collection": "DC\_PROVIDER" }, "index": { "name": "dc\_provider\_idx", "type": "DC\_PROVIDER" }}  
> > }, {  
> > "\_index" : "\_river",  
> > "\_type" : "dc\_practice\_river",  
> > "\_id" : "\_meta",  
> > "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb": { "db": "data-collection", "collection": "DC\_PRACTICE" }, "index": { "name": "dc\_practice\_idx", "type": "DC\_PRACTICE" }}  
> > }, {  
> > "\_index" : "\_river",  
> > "\_type" : "dc\_patient\_topic\_river",  
> > "\_id" : "\_meta",  
> > "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb": { "db": "data-collection", "collection": "DC\_PATIENT\_TOPIC\_DATA" }, "index": { "name": "dc\_patient\_topic\_data\_idx", "type": "DC\_PATIENT\_TOPIC\_DATA" }}  
> > }, {  
> > "\_index" : "\_river",  
> > "\_type" : "dc\_patient\_river",  
> > "\_id" : "\_meta",  
> > "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb": { "db": "data-collection", "collection": "DC\_PATIENT" }, "index": { "name": "dc\_patient\_idx", "type": "DC\_PATIENT" }}  
> > }, {  
> > "\_index" : "\_river",  
> > "\_type" : "dc\_demo\_jursidiction\_river",  
> > "\_id" : "data-collection.DC\_DEMO\_JURISDICTION",  
> > "\_score" : 1.0, "\_source" : {"mongodb":{"\_last\_ts":"{ "$ts" : 1362465631 , "$inc" : 1}"}}  
> > }, {  
> > "\_index" : "\_river",  
> > "\_type" : "dc\_demo\_rule\_metadata\_river",  
> > "\_id" : "\_meta",  
> > "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb": { "db": "data-collection", "collection": "DC\_RULES\_METADATA" }, "index": { "name": "dc\_rule\_metadata\_idx", "type": "DC\_RULES\_METADATA" }}  
> > }, {  
> > "\_index" : "\_river",  
> > "\_type" : "dc\_role\_river",  
> > "\_id" : "\_meta",  
> > "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb": { "db": "data-collection", "collection": "DC\_ROLE" }, "index": { "name": "dc\_role\_idx", "type": "DC\_ROLE" }}  
> > }, {  
> > "\_index" : "\_river",  
> > "\_type" : "dc\_demo\_group\_river",  
> > "\_id" : "\_meta",  
> > "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb": { "db": "data-collection", "collection": "DC\_DEMO\_GROUP" }, "index": { "name": "dc\_demo\_group\_idx", "type": "DC\_DEMO\_GROUP" }}  
> > }, {  
> > "\_index" : "\_river",  
> > "\_type" : "dc\_topic\_river",  
> > "\_id" : "\_meta",  
> > "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb": { "db": "data-collection", "collection": "DC\_TOPIC" }, "index": { "name": "dc\_topic\_idx", "type": "DC\_TOPIC" }}  
> > } ]  
> > }  
> > }
> > 
> > --  
> > 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).
> 
> --  
> 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).

--  
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:** ![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, 2:11pm UTC](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092/14 "2013-03-11T14:11:28Z")

</div>

Hi David,  
i am using mongodb as database. i want to search text using elasticsearch  
in java.

this is my xml configuration

\<elasticsearch:node id="esNode" /\>  
\<elasticsearch:client node="esNode" id="esClient" /\>

properties file is:

cluster.name=dc-cluster  
name=junit.node

# Disable network

discovery.zen.ping.multicast.enabled=false  
node.local=true

# Using less filesystem as possible

index.store.type=memory  
index.store.fs.memory.enabled=true  
index.gateway.type=none  
gateway.type=none

# If ES needs to write something, it's here

path.data=es/twitter

# Index are minimalists by default

index.number\_of\_shards=1  
index.number\_of\_replicas=0

using curl i am trying to create indexes

curl -XPUT "[http://localhost:9200/\_river/dc\_role\_river/\_meta](http://localhost:9200/_river/dc_role_river/_meta)" -d {  
"type": "mongodb",  
"mongodb": {  
"db": "data-collection",  
"collection": "DC\_USER"  
},  
"index": {  
"name": "dc\_user\_idx",  
"type": "DC\_USER"  
}  
}  
this is my java code..

Node node = null;  
node = NodeBuilder.nodeBuilder().node();

```
    Client client = node.client();

```

SearchResponse response =  
client.prepareSearch().setQuery(QueryBuilders.textQuery("firstName",  
"SampleUser")).setIndices("\_river").setTypes("dc\_user\_river").execute().actionGet();

System.out.println(response);  
SearchHit results = response.getHits().getHits();  
System.out.println(results);  
for (SearchHit hit : results) {  
System.out.println(hit.getId()); //prints out the id of the  
document  
result = hit.getSource(); //the retrieved document  
System.out.println(result.keySet());  
}

out put is:

{  
"took" : 281,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 1,  
"successful" : 1,  
"failed" : 0  
},  
"hits" : {  
"total" : 0,  
"max\_score" : null,  
"hits" :   
}  
}

i am not able to get the data.

please help me.

On Monday, March 11, 2013 7:23:48 PM UTC+5:30, David Pilato wrote:

> Hi,
> 
> Just jumping in this thread.
> 
> What are you trying to achieve?  
> Do you want to access to the river to to documents indexed by the river?
> 
> Can you describe a little bit what you are trying to do?  
> Also, have a look at:  
> [Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/guide/reference/java-api/)  
> And [GitHub - elasticsearchfr/hands-on at answers](https://github.com/elasticsearchfr/hands-on/tree/answers)
> 
> To have some information on how to build requests using Java API.
> 
> Hope this help.
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> 
> Le 11 mars 2013 à 14:50, srikanth gone \<[srika...@gmail.com](mailto:srika...@gmail.com) \<javascript:\>\>  
> a écrit :
> 
> i did like this..
> 
> SearchResponse response =  
> client.prepareSearch().setIndices("\_river").setTypes("dc\_user\_river").execute().actionGet();
> 
> output is  
> {  
> "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" : "\_meta",  
> "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
> { "db": "data-collection", "collection": "DC\_USER" },  
> "index": { "name": "dc\_user\_idx", "type": "DC\_USER" }}  
> }, {  
> "\_index" : "\_river",  
> "\_type" : "dc\_user\_river",  
> "\_id" : "\_status",  
> "\_score" : 1.0, "\_source" :  
> {"ok":true,"node":{"id":"Snvd2nvCQB-4hpKUvMQtqA","name":"Jaeger","transport\_address":"inet[/  
> 192.168.10.2:9300]"}}  
> } ]  
> }  
> }
> 
> On Monday, March 11, 2013 6:34:34 PM UTC+5:30, simonw wrote:
> 
> > ok so are you sure you have a 'dc\_user\_river' type?
> > 
> > what happens if your remove the query entirely and just filter by the  
> > 'dc\_user\_river' type?
> > 
> > simon
> > 
> > On Monday, March 11, 2013 1:59:22 PM UTC+1, srikanth gone wrote:
> > 
> > > hi simonw,
> > > 
> > > if i use this code..
> > > 
> > > SearchResponse response = client.prepareSearch().execute().actionGet();
> > > 
> > > System.out.println(response);  
> > > SearchHit results = response.getHits().getHits();  
> > > System.out.println(results);  
> > > for (SearchHit hit : results) {  
> > > System.out.println(hit.getId()); //prints out the id of the  
> > > document  
> > > result = hit.getSource(); //the retrieved document  
> > > }
> > > 
> > > i am getting this output.
> > > 
> > > {  
> > > "took" : 63,  
> > > "timed\_out" : false,  
> > > "\_shards" : {  
> > > "total" : 91,  
> > > "successful" : 91,  
> > > "failed" : 0  
> > > },  
> > > "hits" : {  
> > > "total" : 122,  
> > > "max\_score" : 1.0,  
> > > "hits" : [ {  
> > > "\_index" : "\_river",  
> > > "\_type" : "dc\_demo\_group\_river",  
> > > "\_id" : "data-collection.DC\_DEMO\_GROUP",  
> > > "\_score" : 1.0, "\_source" : {"mongodb":{"\_last\_ts":"{ "$ts" :  
> > > 1362465631 , "$inc" : 1}"}}  
> > > }, {  
> > > "\_index" : "\_river",  
> > > "\_type" : "dc\_provider\_river",  
> > > "\_id" : "\_meta",  
> > > "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
> > > { "db": "data-collection", "collection": "DC\_PROVIDER"  
> > > }, "index": { "name": "dc\_provider\_idx", "type":  
> > > "DC\_PROVIDER" }}  
> > > }, {  
> > > "\_index" : "\_river",  
> > > "\_type" : "dc\_practice\_river",  
> > > "\_id" : "\_meta",  
> > > "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
> > > { "db": "data-collection", "collection": "DC\_PRACTICE"  
> > > }, "index": { "name": "dc\_practice\_idx", "type":  
> > > "DC\_PRACTICE" }}  
> > > }, {  
> > > "\_index" : "\_river",  
> > > "\_type" : "dc\_patient\_topic\_river",  
> > > "\_id" : "\_meta",  
> > > "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
> > > { "db": "data-collection", "collection":  
> > > "DC\_PATIENT\_TOPIC\_DATA" }, "index": { "name":  
> > > "dc\_patient\_topic\_data\_idx", "type": "DC\_PATIENT\_TOPIC\_DATA" }}  
> > > }, {  
> > > "\_index" : "\_river",  
> > > "\_type" : "dc\_patient\_river",  
> > > "\_id" : "\_meta",  
> > > "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
> > > { "db": "data-collection", "collection": "DC\_PATIENT"  
> > > }, "index": { "name": "dc\_patient\_idx", "type":  
> > > "DC\_PATIENT" }}  
> > > }, {  
> > > "\_index" : "\_river",  
> > > "\_type" : "dc\_demo\_jursidiction\_river",  
> > > "\_id" : "data-collection.DC\_DEMO\_JURISDICTION",  
> > > "\_score" : 1.0, "\_source" : {"mongodb":{"\_last\_ts":"{ "$ts" :  
> > > 1362465631 , "$inc" : 1}"}}  
> > > }, {  
> > > "\_index" : "\_river",  
> > > "\_type" : "dc\_demo\_rule\_metadata\_river",  
> > > "\_id" : "\_meta",  
> > > "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
> > > { "db": "data-collection", "collection":  
> > > "DC\_RULES\_METADATA" }, "index": { "name":  
> > > "dc\_rule\_metadata\_idx", "type": "DC\_RULES\_METADATA" }}  
> > > }, {  
> > > "\_index" : "\_river",  
> > > "\_type" : "dc\_role\_river",  
> > > "\_id" : "\_meta",  
> > > "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
> > > { "db": "data-collection", "collection": "DC\_ROLE" },  
> > > "index": { "name": "dc\_role\_idx", "type": "DC\_ROLE" }}  
> > > }, {  
> > > "\_index" : "\_river",  
> > > "\_type" : "dc\_demo\_group\_river",  
> > > "\_id" : "\_meta",  
> > > "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
> > > { "db": "data-collection", "collection": "DC\_DEMO\_GROUP"  
> > > }, "index": { "name": "dc\_demo\_group\_idx", "type":  
> > > "DC\_DEMO\_GROUP" }}  
> > > }, {  
> > > "\_index" : "\_river",  
> > > "\_type" : "dc\_topic\_river",  
> > > "\_id" : "\_meta",  
> > > "\_score" : 1.0, "\_source" : { "type": "mongodb", "mongodb":  
> > > { "db": "data-collection", "collection": "DC\_TOPIC" },  
> > > "index": { "name": "dc\_topic\_idx", "type": "DC\_TOPIC" }}  
> > > } ]  
> > > }  
> > > }
> > > 
> > > > > > > >
> 
> --  
> 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](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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:** ![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:** [March 11, 2013, 2:39pm UTC](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092/15 "2013-03-11T14:39:40Z")

</div>

Let's do it step by step.

Try this:

SearchResponse response = client.prepareSearch().setQuery(QueryBuilders.textQuery("firstName", "SampleUser")).setIndices("dc\_user\_idx").setTypes("DC\_USER").execute().actionGet();

If it does not work, can you do:  
curl "localhost:9200/dc\_user\_idx/\_search?q=\*&pretty"

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 11 mars 2013 à 15:11, srikanth gone [srikanthg93@gmail.com](mailto:srikanthg93@gmail.com) a écrit :

> Hi David,  
> i am using mongodb as database. i want to search text using elasticsearch in java.
> 
> this is my xml configuration
> 
> \<elasticsearch:node id="esNode" /\>  
> \<elasticsearch:client node="esNode" id="esClient" /\>
> 
> properties file is:
> 
> cluster.name=dc-cluster  
> name=junit.node
> 
> # Disable network
> 
> discovery.zen.ping.multicast.enabled=false  
> node.local=true
> 
> # Using less filesystem as possible
> 
> index.store.type=memory  
> index.store.fs.memory.enabled=true  
> index.gateway.type=none  
> gateway.type=none
> 
> # If ES needs to write something, it's here
> 
> path.data=es/twitter
> 
> # Index are minimalists by default
> 
> index.number\_of\_shards=1  
> index.number\_of\_replicas=0
> 
> using curl i am trying to create indexes
> 
> curl -XPUT "[http://localhost:9200/\_river/dc\_role\_river/\_meta](http://localhost:9200/_river/dc_role_river/_meta)" -d {  
> "type": "mongodb",  
> "mongodb": {  
> "db": "data-collection",  
> "collection": "DC\_USER"  
> },  
> "index": {  
> "name": "dc\_user\_idx",  
> "type": "DC\_USER"  
> }  
> }  
> this is my java code..
> 
> Node node = null;  
> node = NodeBuilder.nodeBuilder().node();
> 
> ```
> Client client = node.client();
> 
> ```
> 
> SearchResponse response = client.prepareSearch().setQuery(QueryBuilders.textQuery("firstName", "SampleUser")).setIndices("\_river").setTypes("dc\_user\_river").execute().actionGet();
> 
> System.out.println(response);  
> SearchHit results = response.getHits().getHits();  
> System.out.println(results);  
> for (SearchHit hit : results) {  
> System.out.println(hit.getId()); //prints out the id of the document  
> result = hit.getSource(); //the retrieved document  
> System.out.println(result.keySet());  
> }
> 
> out put is:
> 
> {  
> "took" : 281,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 1,  
> "successful" : 1,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 0,  
> "max\_score" : null,  
> "hits" :   
> }  
> }
> 
> i am not able to get the data.
> 
> please 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:** ![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, 3:25pm UTC](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092/16 "2013-03-11T15:25:14Z")

</div>

Hi David,  
i have tried what you have suggested. its working..  
output is

{  
"took" : 78,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 1,  
"failed" : 4,  
"failures" : [ {  
"index" : "dc\_user\_idx",  
"shard" : 0,  
"status" : 500,  
"reason" : "No active shards"  
}, {  
"index" : "dc\_user\_idx",  
"shard" : 1,  
"status" : 500,  
"reason" : "No active shards"  
}, {  
"index" : "dc\_user\_idx",  
"shard" : 2,  
"status" : 500,  
"reason" : "No active shards"  
}, {  
"index" : "dc\_user\_idx",  
"shard" : 3,  
"status" : 500,  
"reason" : "No active shards"  
} ]  
},  
"hits" : {  
"total" : 1,  
"max\_score" : 0.30685282,  
"hits" : [ {  
"\_index" : "dc\_user\_idx",  
"\_type" : "DC\_USER",  
"\_id" : "1DQlnc2ZQD-QFzbhi3KNpg",  
"\_score" : 0.30685282, "\_source" :  
{"userName":"SampleUser","firstName":"SampleUser","lastName":"SampleUser"}  
} ]  
}  
}

when i am i have change the text, i.e instead of SampleUser, i have use  
NormalUser, its not fetch data.. but record is there in db.

On Monday, March 11, 2013 8:09:40 PM UTC+5:30, David Pilato wrote:

> Let's do it step by step.
> 
> Try this:
> 
> SearchResponse response =  
> client.prepareSearch().setQuery(QueryBuilders.textQuery("firstName",  
> "SampleUser")).setIndices("dc\_user\_idx").setTypes("DC\_USER").execute().actionGet();
> 
> If it does not work, can you do:  
> curl "localhost:9200/dc\_user\_idx/\_search?q=\*&pretty"
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> 
> Le 11 mars 2013 à 15:11, srikanth gone \<[srika...@gmail.com](mailto:srika...@gmail.com) \<javascript:\>\>  
> a écrit :
> 
> Hi David,  
> i am using mongodb as database. i want to search text using elasticsearch  
> in java.
> 
> this is my xml configuration
> 
> \<elasticsearch:node id="esNode" /\>  
> \<elasticsearch:client node="esNode" id="esClient" /\>
> 
> properties file is:
> 
> cluster.name=dc-cluster  
> name=junit.node
> 
> # Disable network
> 
> discovery.zen.ping.multicast.enabled=false  
> node.local=true
> 
> # Using less filesystem as possible
> 
> index.store.type=memory  
> index.store.fs.memory.enabled=true  
> index.gateway.type=none  
> gateway.type=none
> 
> # If ES needs to write something, it's here
> 
> path.data=es/twitter
> 
> # Index are minimalists by default
> 
> index.number\_of\_shards=1  
> index.number\_of\_replicas=0
> 
> using curl i am trying to create indexes
> 
> curl -XPUT "[http://localhost:9200/\_river/dc\_role\_river/\_meta](http://localhost:9200/_river/dc_role_river/_meta)" -d {  
> "type": "mongodb",  
> "mongodb": {  
> "db": "data-collection",  
> "collection": "DC\_USER"  
> },  
> "index": {  
> "name": "dc\_user\_idx",  
> "type": "DC\_USER"  
> }  
> }  
> this is my java code..
> 
> Node node = null;  
> node = NodeBuilder.nodeBuilder().node();
> 
> ```
> Client client = node.client();
> 
> ```
> 
> SearchResponse response =  
> client.prepareSearch().setQuery(QueryBuilders.textQuery("firstName",  
> "SampleUser")).setIndices("\_river").setTypes("dc\_user\_river").execute().actionGet();
> 
> System.out.println(response);  
> SearchHit results = response.getHits().getHits();  
> System.out.println(results);  
> for (SearchHit hit : results) {  
> System.out.println(hit.getId()); //prints out the id of the  
> document  
> result = hit.getSource(); //the retrieved document  
> System.out.println(result.keySet());  
> }
> 
> out put is:
> 
> {  
> "took" : 281,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 1,  
> "successful" : 1,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 0,  
> "max\_score" : null,  
> "hits" :   
> }  
> }
> 
> i am not able to get the data.
> 
> please 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:** ![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:** [March 11, 2013, 3:28pm UTC](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092/17 "2013-03-11T15:28:24Z")

</div>

You have 4 failing shards. Perhaps the document you are looking for is in one of theses shards.  
You should try to have a _yellow_ cluster before searching in it.

Try to restart from scratch.

curl -XDELETE [http://localhost:9200/](http://localhost:9200/)

_WARNING_: it will delete all your indexes and rivers.

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 11 mars 2013 à 16:25, srikanth gone [srikanthg93@gmail.com](mailto:srikanthg93@gmail.com) a écrit :

> Hi David,  
> i have tried what you have suggested. its working..  
> output is
> 
> {  
> "took" : 78,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 1,  
> "failed" : 4,  
> "failures" : [ {  
> "index" : "dc\_user\_idx",  
> "shard" : 0,  
> "status" : 500,  
> "reason" : "No active shards"  
> }, {  
> "index" : "dc\_user\_idx",  
> "shard" : 1,  
> "status" : 500,  
> "reason" : "No active shards"  
> }, {  
> "index" : "dc\_user\_idx",  
> "shard" : 2,  
> "status" : 500,  
> "reason" : "No active shards"  
> }, {  
> "index" : "dc\_user\_idx",  
> "shard" : 3,  
> "status" : 500,  
> "reason" : "No active shards"  
> } ]  
> },  
> "hits" : {  
> "total" : 1,  
> "max\_score" : 0.30685282,  
> "hits" : [ {  
> "\_index" : "dc\_user\_idx",  
> "\_type" : "DC\_USER",  
> "\_id" : "1DQlnc2ZQD-QFzbhi3KNpg",  
> "\_score" : 0.30685282, "\_source" : {"userName":"SampleUser","firstName":"SampleUser","lastName":"SampleUser"}  
> } ]  
> }  
> }
> 
> when i am i have change the text, i.e instead of SampleUser, i have use NormalUser, its not fetch data.. but record is there in db.
> 
> On Monday, March 11, 2013 8:09:40 PM UTC+5:30, David Pilato wrote:  
> Let's do it step by step.
> 
> Try this:
> 
> SearchResponse response = client.prepareSearch().setQuery(QueryBuilders.textQuery("firstName", "SampleUser")).setIndices("dc\_user\_idx").setTypes("DC\_USER").execute().actionGet();
> 
> If it does not work, can you do:  
> curl "localhost:9200/dc\_user\_idx/\_search?q=\*&pretty"
> 
> --  
> David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
> @dadoonet | @elasticsearchfr | @scrutmydocs
> 
> Le 11 mars 2013 à 15:11, srikanth gone [srika...@gmail.com](mailto:srika...@gmail.com) a écrit :
> 
> > Hi David,  
> > i am using mongodb as database. i want to search text using elasticsearch in java.
> > 
> > this is my xml configuration
> > 
> > \<elasticsearch:node id="esNode" /\>  
> > \<elasticsearch:client node="esNode" id="esClient" /\>
> > 
> > properties file is:
> > 
> > cluster.name=dc-cluster  
> > name=junit.node
> > 
> > # Disable network
> > 
> > discovery.zen.ping.multicast.enabled=false  
> > node.local=true
> > 
> > # Using less filesystem as possible
> > 
> > index.store.type=memory  
> > index.store.fs.memory.enabled=true  
> > index.gateway.type=none  
> > gateway.type=none
> > 
> > # If ES needs to write something, it's here
> > 
> > path.data=es/twitter
> > 
> > # Index are minimalists by default
> > 
> > index.number\_of\_shards=1  
> > index.number\_of\_replicas=0
> > 
> > using curl i am trying to create indexes
> > 
> > curl -XPUT "[http://localhost:9200/\_river/dc\_role\_river/\_meta](http://localhost:9200/_river/dc_role_river/_meta)" -d {  
> > "type": "mongodb",  
> > "mongodb": {  
> > "db": "data-collection",  
> > "collection": "DC\_USER"  
> > },  
> > "index": {  
> > "name": "dc\_user\_idx",  
> > "type": "DC\_USER"  
> > }  
> > }  
> > this is my java code..
> > 
> > Node node = null;  
> > node = NodeBuilder.nodeBuilder().node();
> > 
> > ```
> > Client client = node.client();
> > 
> > ```
> > 
> > SearchResponse response = client.prepareSearch().setQuery(QueryBuilders.textQuery("firstName", "SampleUser")).setIndices("\_river").setTypes("dc\_user\_river").execute().actionGet();
> > 
> > System.out.println(response);  
> > SearchHit results = response.getHits().getHits();  
> > System.out.println(results);  
> > for (SearchHit hit : results) {  
> > System.out.println(hit.getId()); //prints out the id of the document  
> > result = hit.getSource(); //the retrieved document  
> > System.out.println(result.keySet());  
> > }
> > 
> > out put is:
> > 
> > {  
> > "took" : 281,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 1,  
> > "successful" : 1,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 0,  
> > "max\_score" : null,  
> > "hits" :   
> > }  
> > }
> > 
> > i am not able to get the data.
> > 
> > please 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).

--  
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:** ![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, 4:17pm UTC](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092/18 "2013-03-11T16:17:52Z")

</div>

Hi David..  
i have deleted curl.. and restarted.  
i have replaced text like this..  
SearchResponse response =  
client.prepareSearch().setQuery(QueryBuilders.textQuery("firstName",  
"Ashok")).setIndices("dc\_user\_idx").setTypes("DC\_USER").execute().actionGet();

output..but already record is there  
{  
"took" : 578,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 3,  
"failed" : 2,  
"failures" : [ {  
"index" : "dc\_user\_idx",  
"shard" : 1,  
"status" : 500,  
"reason" : "No active shards"  
}, {  
"index" : "dc\_user\_idx",  
"shard" : 3,  
"status" : 500,  
"reason" : "No active shards"  
} ]  
},  
"hits" : {  
"total" : 0,  
"max\_score" : null,  
"hits" :   
}  
}

please help me

On Monday, March 11, 2013 8:58:24 PM UTC+5:30, David Pilato wrote:

> You have 4 failing shards. Perhaps the document you are looking for is in  
> one of theses shards.  
> You should try to have a _yellow_ cluster before searching in it.
> 
> Try to restart from scratch.
> 
> curl -XDELETE [http://localhost:9200/](http://localhost:9200/)
> 
> _WARNING_: it will delete all your indexes and rivers.
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> 
> Le 11 mars 2013 à 16:25, srikanth gone \<[srika...@gmail.com](mailto:srika...@gmail.com) \<javascript:\>\>  
> a écrit :
> 
> Hi David,  
> i have tried what you have suggested. its working..  
> output is
> 
> {  
> "took" : 78,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 1,  
> "failed" : 4,  
> "failures" : [ {  
> "index" : "dc\_user\_idx",  
> "shard" : 0,  
> "status" : 500,  
> "reason" : "No active shards"  
> }, {  
> "index" : "dc\_user\_idx",  
> "shard" : 1,  
> "status" : 500,  
> "reason" : "No active shards"  
> }, {  
> "index" : "dc\_user\_idx",  
> "shard" : 2,  
> "status" : 500,  
> "reason" : "No active shards"  
> }, {  
> "index" : "dc\_user\_idx",  
> "shard" : 3,  
> "status" : 500,  
> "reason" : "No active shards"  
> } ]  
> },  
> "hits" : {  
> "total" : 1,  
> "max\_score" : 0.30685282,  
> "hits" : [ {  
> "\_index" : "dc\_user\_idx",  
> "\_type" : "DC\_USER",  
> "\_id" : "1DQlnc2ZQD-QFzbhi3KNpg",  
> "\_score" : 0.30685282, "\_source" :  
> {"userName":"SampleUser","firstName":"SampleUser","lastName":"SampleUser"}  
> } ]  
> }  
> }
> 
> when i am i have change the text, i.e instead of SampleUser, i have use  
> NormalUser, its not fetch data.. but record is there in db.
> 
> On Monday, March 11, 2013 8:09:40 PM UTC+5:30, David Pilato wrote:
> 
> > Let's do it step by step.
> > 
> > Try this:
> > 
> > SearchResponse response =  
> > client.prepareSearch().setQuery(QueryBuilders.textQuery("firstName",  
> > "SampleUser")).setIndices("dc\_user\_idx").setTypes("DC\_USER").execute().actionGet();
> > 
> > If it does not work, can you do:  
> > curl "localhost:9200/dc\_user\_idx/\_search?q=\*&pretty"
> > 
> > --  
> > _David Pilato_ | _Technical Advocate_ | \*[Elasticsearch.com](http://Elasticsearch.com)[http://elasticsearch.com/](http://elasticsearch.com/)  
> > \*  
> > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> > | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> > 
> > Le 11 mars 2013 à 15:11, srikanth gone [srika...@gmail.com](mailto:srika...@gmail.com) a écrit :
> > 
> > Hi David,  
> > i am using mongodb as database. i want to search text using  
> > elasticsearch in java.
> > 
> > this is my xml configuration
> > 
> > \<elasticsearch:node id="esNode" /\>  
> > \<elasticsearch:client node="esNode" id="esClient" /\>
> > 
> > properties file is:
> > 
> > cluster.name=dc-cluster  
> > name=junit.node
> > 
> > # Disable network
> > 
> > discovery.zen.ping.multicast.enabled=false  
> > node.local=true
> > 
> > # Using less filesystem as possible
> > 
> > index.store.type=memory  
> > index.store.fs.memory.enabled=true  
> > index.gateway.type=none  
> > gateway.type=none
> > 
> > # If ES needs to write something, it's here
> > 
> > path.data=es/twitter
> > 
> > # Index are minimalists by default
> > 
> > index.number\_of\_shards=1  
> > index.number\_of\_replicas=0
> > 
> > using curl i am trying to create indexes
> > 
> > curl -XPUT "[http://localhost:9200/\_river/dc\_role\_river/\_meta](http://localhost:9200/_river/dc_role_river/_meta)" -d {  
> > "type": "mongodb",  
> > "mongodb": {  
> > "db": "data-collection",  
> > "collection": "DC\_USER"  
> > },  
> > "index": {  
> > "name": "dc\_user\_idx",  
> > "type": "DC\_USER"  
> > }  
> > }  
> > this is my java code..
> > 
> > Node node = null;  
> > node = NodeBuilder.nodeBuilder().node();
> > 
> > ```
> > Client client = node.client();
> > 
> > ```
> > 
> > SearchResponse response =  
> > client.prepareSearch().setQuery(QueryBuilders.textQuery("firstName",  
> > "SampleUser")).setIndices("\_river").setTypes("dc\_user\_river").execute().actionGet();
> > 
> > System.out.println(response);  
> > SearchHit results = response.getHits().getHits();  
> > System.out.println(results);  
> > for (SearchHit hit : results) {  
> > System.out.println(hit.getId()); //prints out the id of the  
> > document  
> > result = hit.getSource(); //the retrieved document  
> > System.out.println(result.keySet());  
> > }
> > 
> > out put is:
> > 
> > {  
> > "took" : 281,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 1,  
> > "successful" : 1,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 0,  
> > "max\_score" : null,  
> > "hits" :   
> > }  
> > }
> > 
> > i am not able to get the data.
> > 
> > please 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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:** ![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:** [March 11, 2013, 4:25pm UTC](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092/19 "2013-03-11T16:25:14Z")

</div>

Sounds like you are creating index in Java, don't you?  
If so, wait for a yellow cluster before creating the river and searching for anything.

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

Le 11 mars 2013 à 17:17, srikanth gone [srikanthg93@gmail.com](mailto:srikanthg93@gmail.com) a écrit :

> Hi David..  
> i have deleted curl.. and restarted.  
> i have replaced text like this..  
> SearchResponse response = client.prepareSearch().setQuery(QueryBuilders.textQuery("firstName", "Ashok")).setIndices("dc\_user\_idx").setTypes("DC\_USER").execute().actionGet();
> 
> output..but already record is there  
> {  
> "took" : 578,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 3,  
> "failed" : 2,  
> "failures" : [ {  
> "index" : "dc\_user\_idx",  
> "shard" : 1,  
> "status" : 500,  
> "reason" : "No active shards"  
> }, {  
> "index" : "dc\_user\_idx",  
> "shard" : 3,  
> "status" : 500,  
> "reason" : "No active shards"  
> } ]  
> },  
> "hits" : {  
> "total" : 0,  
> "max\_score" : null,  
> "hits" :   
> }  
> }
> 
> please help me
> 
> On Monday, March 11, 2013 8:58:24 PM UTC+5:30, David Pilato wrote:
> 
> > You have 4 failing shards. Perhaps the document you are looking for is in one of theses shards.  
> > You should try to have a _yellow_ cluster before searching in it.
> > 
> > Try to restart from scratch.
> > 
> > curl -XDELETE [http://localhost:9200/](http://localhost:9200/)
> > 
> > _WARNING_: it will delete all your indexes and rivers.
> > 
> > --  
> > David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
> > @dadoonet | @elasticsearchfr | @scrutmydocs
> > 
> > Le 11 mars 2013 à 16:25, srikanth gone [srika...@gmail.com](mailto:srika...@gmail.com) a écrit :
> > 
> > > Hi David,  
> > > i have tried what you have suggested. its working..  
> > > output is
> > > 
> > > {  
> > > "took" : 78,  
> > > "timed\_out" : false,  
> > > "\_shards" : {  
> > > "total" : 5,  
> > > "successful" : 1,  
> > > "failed" : 4,  
> > > "failures" : [ {  
> > > "index" : "dc\_user\_idx",  
> > > "shard" : 0,  
> > > "status" : 500,  
> > > "reason" : "No active shards"  
> > > }, {  
> > > "index" : "dc\_user\_idx",  
> > > "shard" : 1,  
> > > "status" : 500,  
> > > "reason" : "No active shards"  
> > > }, {  
> > > "index" : "dc\_user\_idx",  
> > > "shard" : 2,  
> > > "status" : 500,  
> > > "reason" : "No active shards"  
> > > }, {  
> > > "index" : "dc\_user\_idx",  
> > > "shard" : 3,  
> > > "status" : 500,  
> > > "reason" : "No active shards"  
> > > } ]  
> > > },  
> > > "hits" : {  
> > > "total" : 1,  
> > > "max\_score" : 0.30685282,  
> > > "hits" : [ {  
> > > "\_index" : "dc\_user\_idx",  
> > > "\_type" : "DC\_USER",  
> > > "\_id" : "1DQlnc2ZQD-QFzbhi3KNpg",  
> > > "\_score" : 0.30685282, "\_source" : {"userName":"SampleUser","firstName":"SampleUser","lastName":"SampleUser"}  
> > > } ]  
> > > }  
> > > }
> > > 
> > > when i am i have change the text, i.e instead of SampleUser, i have use NormalUser, its not fetch data.. but record is there in db.
> > > 
> > > On Monday, March 11, 2013 8:09:40 PM UTC+5:30, David Pilato wrote:
> > > 
> > > > Let's do it step by step.
> > > > 
> > > > Try this:
> > > > 
> > > > SearchResponse response = client.prepareSearch().setQuery(QueryBuilders.textQuery("firstName", "SampleUser")).setIndices("dc\_user\_idx").setTypes("DC\_USER").execute().actionGet();
> > > > 
> > > > If it does not work, can you do:  
> > > > curl "localhost:9200/dc\_user\_idx/\_search?q=\*&pretty"
> > > > 
> > > > --  
> > > > David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
> > > > @dadoonet | @elasticsearchfr | @scrutmydocs
> > > > 
> > > > Le 11 mars 2013 à 15:11, srikanth gone [srika...@gmail.com](mailto:srika...@gmail.com) a écrit :
> > > > 
> > > > > Hi David,  
> > > > > i am using mongodb as database. i want to search text using elasticsearch in java.
> > > > > 
> > > > > this is my xml configuration
> > > > > 
> > > > > \<elasticsearch:node id="esNode" /\>  
> > > > > \<elasticsearch:client node="esNode" id="esClient" /\>
> > > > > 
> > > > > properties file is:
> > > > > 
> > > > > cluster.name=dc-cluster  
> > > > > name=junit.node
> > > > > 
> > > > > # Disable network
> > > > > 
> > > > > discovery.zen.ping.multicast.enabled=false  
> > > > > node.local=true
> > > > > 
> > > > > # Using less filesystem as possible
> > > > > 
> > > > > index.store.type=memory  
> > > > > index.store.fs.memory.enabled=true  
> > > > > index.gateway.type=none  
> > > > > gateway.type=none
> > > > > 
> > > > > # If ES needs to write something, it's here
> > > > > 
> > > > > path.data=es/twitter
> > > > > 
> > > > > # Index are minimalists by default
> > > > > 
> > > > > index.number\_of\_shards=1  
> > > > > index.number\_of\_replicas=0
> > > > > 
> > > > > using curl i am trying to create indexes
> > > > > 
> > > > > curl -XPUT "[http://localhost:9200/\_river/dc\_role\_river/\_meta](http://localhost:9200/_river/dc_role_river/_meta)" -d {  
> > > > > "type": "mongodb",  
> > > > > "mongodb": {  
> > > > > "db": "data-collection",  
> > > > > "collection": "DC\_USER"  
> > > > > },  
> > > > > "index": {  
> > > > > "name": "dc\_user\_idx",  
> > > > > "type": "DC\_USER"  
> > > > > }  
> > > > > }  
> > > > > this is my java code..
> > > > > 
> > > > > Node node = null;  
> > > > > node = NodeBuilder.nodeBuilder().node();
> > > > > 
> > > > > ```
> > > > > Client client = node.client();
> > > > > 
> > > > > ```
> > > > > 
> > > > > SearchResponse response = client.prepareSearch().setQuery(QueryBuilders.textQuery("firstName", "SampleUser")).setIndices("\_river").setTypes("dc\_user\_river").execute().actionGet();
> > > > > 
> > > > > System.out.println(response);  
> > > > > SearchHit results = response.getHits().getHits();  
> > > > > System.out.println(results);  
> > > > > for (SearchHit hit : results) {  
> > > > > System.out.println(hit.getId()); //prints out the id of the document  
> > > > > result = hit.getSource(); //the retrieved document  
> > > > > System.out.println(result.keySet());  
> > > > > }
> > > > > 
> > > > > out put is:
> > > > > 
> > > > > {  
> > > > > "took" : 281,  
> > > > > "timed\_out" : false,  
> > > > > "\_shards" : {  
> > > > > "total" : 1,  
> > > > > "successful" : 1,  
> > > > > "failed" : 0  
> > > > > },  
> > > > > "hits" : {  
> > > > > "total" : 0,  
> > > > > "max\_score" : null,  
> > > > > "hits" :   
> > > > > }  
> > > > > }
> > > > > 
> > > > > i am not able to get the data.
> > > > > 
> > > > > please 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).  
> > > --  
> > > 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).

--  
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:** ![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 12, 2013, 6:17am UTC](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092/20 "2013-03-12T06:17:00Z")

</div>

HI David, i have created indexes using CURL in one batch file.(.bat)

curl -XPUT "[http://localhost:9200/\_river/dc\_user\_river/\_meta](http://localhost:9200/_river/dc_user_river/_meta)" -d {  
"type": "mongodb",  
"mongodb": {  
"db": "data-collection",  
"collection": "DC\_USER"  
},  
"index": {  
"name": "dc\_user\_idx",  
"type": "DC\_USER"  
}  
}  
like this ..

On Monday, March 11, 2013 9:55:14 PM UTC+5:30, David Pilato wrote:

> Sounds like you are creating index in Java, don't you?  
> If so, wait for a yellow cluster before creating the river and searching  
> for anything.
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 11 mars 2013 à 17:17, srikanth gone \<[srika...@gmail.com](mailto:srika...@gmail.com) \<javascript:\>\>  
> a écrit :
> 
> Hi David..  
> i have deleted curl.. and restarted.  
> i have replaced text like this..  
> SearchResponse response =  
> client.prepareSearch().setQuery(QueryBuilders.textQuery("firstName",  
> "Ashok")).setIndices("dc\_user\_idx").setTypes("DC\_USER").execute().actionGet();
> 
> output..but already record is there  
> {  
> "took" : 578,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 3,  
> "failed" : 2,  
> "failures" : [ {  
> "index" : "dc\_user\_idx",  
> "shard" : 1,  
> "status" : 500,  
> "reason" : "No active shards"  
> }, {  
> "index" : "dc\_user\_idx",  
> "shard" : 3,  
> "status" : 500,  
> "reason" : "No active shards"  
> } ]  
> },  
> "hits" : {  
> "total" : 0,  
> "max\_score" : null,  
> "hits" :   
> }  
> }
> 
> please help me
> 
> On Monday, March 11, 2013 8:58:24 PM UTC+5:30, David Pilato wrote:
> 
> > You have 4 failing shards. Perhaps the document you are looking for is in  
> > one of theses shards.  
> > You should try to have a _yellow_ cluster before searching in it.
> > 
> > Try to restart from scratch.
> > 
> > curl -XDELETE [http://localhost:9200/](http://localhost:9200/)
> > 
> > _WARNING_: it will delete all your indexes and rivers.
> > 
> > --  
> > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> > | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> > 
> > Le 11 mars 2013 à 16:25, srikanth gone [srika...@gmail.com](mailto:srika...@gmail.com) a écrit :
> > 
> > Hi David,  
> > i have tried what you have suggested. its working..  
> > output is
> > 
> > {  
> > "took" : 78,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 1,  
> > "failed" : 4,  
> > "failures" : [ {  
> > "index" : "dc\_user\_idx",  
> > "shard" : 0,  
> > "status" : 500,  
> > "reason" : "No active shards"  
> > }, {  
> > "index" : "dc\_user\_idx",  
> > "shard" : 1,  
> > "status" : 500,  
> > "reason" : "No active shards"  
> > }, {  
> > "index" : "dc\_user\_idx",  
> > "shard" : 2,  
> > "status" : 500,  
> > "reason" : "No active shards"  
> > }, {  
> > "index" : "dc\_user\_idx",  
> > "shard" : 3,  
> > "status" : 500,  
> > "reason" : "No active shards"  
> > } ]  
> > },  
> > "hits" : {  
> > "total" : 1,  
> > "max\_score" : 0.30685282,  
> > "hits" : [ {  
> > "\_index" : "dc\_user\_idx",  
> > "\_type" : "DC\_USER",  
> > "\_id" : "1DQlnc2ZQD-QFzbhi3KNpg",  
> > "\_score" : 0.30685282, "\_source" :  
> > {"userName":"SampleUser","firstName":"SampleUser","lastName":"SampleUser"}  
> > } ]  
> > }  
> > }
> > 
> > when i am i have change the text, i.e instead of SampleUser, i have use  
> > NormalUser, its not fetch data.. but record is there in db.
> > 
> > On Monday, March 11, 2013 8:09:40 PM UTC+5:30, David Pilato wrote:
> > 
> > > Let's do it step by step.
> > > 
> > > Try this:
> > > 
> > > SearchResponse response =  
> > > client.prepareSearch().setQuery(QueryBuilders.textQuery("firstName",  
> > > "SampleUser")).setIndices("dc\_user\_idx").setTypes("DC\_USER").execute().actionGet();
> > > 
> > > If it does not work, can you do:  
> > > curl "localhost:9200/dc\_user\_idx/\_search?q=\*&pretty"
> > > 
> > > --  
> > > _David Pilato_ | _Technical Advocate_ | \*[Elasticsearch.com](http://Elasticsearch.com)[http://elasticsearch.com/](http://elasticsearch.com/)  
> > > \*  
> > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> > > | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> > > 
> > > Le 11 mars 2013 à 15:11, srikanth gone [srika...@gmail.com](mailto:srika...@gmail.com) a écrit :
> > > 
> > > Hi David,  
> > > i am using mongodb as database. i want to search text using  
> > > elasticsearch in java.
> > > 
> > > this is my xml configuration
> > > 
> > > \<elasticsearch:node id="esNode" /\>  
> > > \<elasticsearch:client node="esNode" id="esClient" /\>
> > > 
> > > properties file is:
> > > 
> > > cluster.name=dc-cluster  
> > > name=junit.node
> > > 
> > > # Disable network
> > > 
> > > discovery.zen.ping.multicast.enabled=false  
> > > node.local=true
> > > 
> > > # Using less filesystem as possible
> > > 
> > > index.store.type=memory  
> > > index.store.fs.memory.enabled=true  
> > > index.gateway.type=none  
> > > gateway.type=none
> > > 
> > > # If ES needs to write something, it's here
> > > 
> > > path.data=es/twitter
> > > 
> > > # Index are minimalists by default
> > > 
> > > index.number\_of\_shards=1  
> > > index.number\_of\_replicas=0
> > > 
> > > using curl i am trying to create indexes
> > > 
> > > curl -XPUT "[http://localhost:9200/\_river/dc\_role\_river/\_meta](http://localhost:9200/_river/dc_role_river/_meta)" -d {  
> > > "type": "mongodb",  
> > > "mongodb": {  
> > > "db": "data-collection",  
> > > "collection": "DC\_USER"  
> > > },  
> > > "index": {  
> > > "name": "dc\_user\_idx",  
> > > "type": "DC\_USER"  
> > > }  
> > > }  
> > > this is my java code..
> > > 
> > > Node node = null;  
> > > node = NodeBuilder.nodeBuilder().node();
> > > 
> > > ```
> > > Client client = node.client();
> > > 
> > > ```
> > > 
> > > SearchResponse response =  
> > > client.prepareSearch().setQuery(QueryBuilders.textQuery("firstName",  
> > > "SampleUser")).setIndices("\_river").setTypes("dc\_user\_river").execute().actionGet();
> > > 
> > > System.out.println(response);  
> > > SearchHit results = response.getHits().getHits();  
> > > System.out.println(results);  
> > > for (SearchHit hit : results) {  
> > > System.out.println(hit.getId()); //prints out the id of the  
> > > document  
> > > result = hit.getSource(); //the retrieved document  
> > > System.out.println(result.keySet());  
> > > }
> > > 
> > > out put is:
> > > 
> > > {  
> > > "took" : 281,  
> > > "timed\_out" : false,  
> > > "\_shards" : {  
> > > "total" : 1,  
> > > "successful" : 1,  
> > > "failed" : 0  
> > > },  
> > > "hits" : {  
> > > "total" : 0,  
> > > "max\_score" : null,  
> > > "hits" :   
> > > }  
> > > }
> > > 
> > > i am not able to get the data.
> > > 
> > > please 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > 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](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

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

[Next page](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092.md?page=2)
