# 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:** 7\
**Page:** 2

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

</div>

hi David, i have cleaned mongo Database and elastic server data folder..

and restarted server.. created 5 records in DC\_USER table..

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

when i call this query its not fetching data..

the output is:

{  
"took" : 47,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 2,  
"failed" : 3,  
"failures" : [ {  
"index" : "dc\_user\_idx",  
"shard" : 0,  
"status" : 500,  
"reason" : "No active shards"  
}, {  
"index" : "dc\_user\_idx",  
"shard" : 3,  
"status" : 500,  
"reason" : "No active shards"  
}, {  
"index" : "dc\_user\_idx",  
"shard" : 4,  
"status" : 500,  
"reason" : "No active shards"  
} ]  
},  
"hits" : {  
"total" : 0,  
"max\_score" : null,  
"hits" :   
}  
}  
how to resolve this problem..

On Tuesday, March 12, 2013 11:47:00 AM UTC+5:30, srikanth gone wrote:

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

</div>

Ok. Follow theses steps:

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

curl -XPUT '[http://localhost:9200/dc\_user\_idx](http://localhost:9200/dc_user_idx)' -d '{  
"settings" : {  
"index" : {  
"number\_of\_shards" : 1,  
"number\_of\_replicas" : 0  
}  
}  
}'

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"  
}  
}

curl '[http://localhost:9200/\_cluster/health?pretty=true](http://localhost:9200/_cluster/health?pretty=true)'

Your cluster should be "status":"green" (or at least yellow - due to the river).  
If not yellow or green, try to have a clean and fresh installation of your elasticsearch.

One more question: are you running more than one node?

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

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

> hi David, i have cleaned mongo Database and elastic server data folder..
> 
> and restarted server.. created 5 records in DC\_USER table..
> 
> SearchResponse response = client.prepareSearch().setQuery(QueryBuilders.textQuery("firstName", "admin")).setIndices("dc\_user\_idx").setTypes("DC\_USER").execute().actionGet();
> 
> when i call this query its not fetching data..
> 
> the output is:
> 
> {  
> "took" : 47,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 2,  
> "failed" : 3,  
> "failures" : [ {  
> "index" : "dc\_user\_idx",  
> "shard" : 0,  
> "status" : 500,  
> "reason" : "No active shards"  
> }, {  
> "index" : "dc\_user\_idx",  
> "shard" : 3,  
> "status" : 500,  
> "reason" : "No active shards"  
> }, {  
> "index" : "dc\_user\_idx",  
> "shard" : 4,  
> "status" : 500,  
> "reason" : "No active shards"  
> } ]  
> },  
> "hits" : {  
> "total" : 0,  
> "max\_score" : null,  
> "hits" :   
> }  
> }  
> how to resolve this problem..
> 
> On Tuesday, March 12, 2013 11:47:00 AM UTC+5:30, srikanth gone wrote:  
> 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) 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 [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, 10:29am UTC](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092/23 "2013-03-12T10:29:48Z")

</div>

Hi David,

Thanks you very much.. its working fine.. i have configured new elastic  
search..

how to search text without specifying fieldName.. which method is  
better.. can you suggest me..

On Tuesday, March 12, 2013 2:46:32 PM UTC+5:30, David Pilato wrote:

> Ok. Follow theses steps:
> 
> curl -XDELETE [http://localhost:9200/](http://localhost:9200/)
> 
> curl -XPUT '[http://localhost:9200/dc\_user\_idx](http://localhost:9200/dc_user_idx)' -d '{  
> "settings" : {  
> "index" : {  
> "number\_of\_shards" : 1,  
> "number\_of\_replicas" : 0  
> }  
> }  
> }'
> 
> 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"  
> }  
> }
> 
> curl '[http://localhost:9200/\_cluster/health?pretty=true](http://localhost:9200/_cluster/health?pretty=true)'
> 
> Your cluster should be "status":"green" (or at least yellow - due to the  
> river).  
> If not yellow or green, try to have a clean and fresh installation of your  
> elasticsearch.
> 
> One more question: are you running more than one node?
> 
> --  
> _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 12 mars 2013 à 08:07, srikanth gone \<[srika...@gmail.com](mailto:srika...@gmail.com) \<javascript:\>\>  
> a écrit :
> 
> hi David, i have cleaned mongo Database and elastic server data folder..
> 
> and restarted server.. created 5 records in DC\_USER table..
> 
> SearchResponse response =  
> client.prepareSearch().setQuery(QueryBuilders.textQuery("firstName",  
> "admin")).setIndices("dc\_user\_idx").setTypes("DC\_USER").execute().actionGet();
> 
> when i call this query its not fetching data..
> 
> the output is:
> 
> {  
> "took" : 47,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 2,  
> "failed" : 3,  
> "failures" : [ {  
> "index" : "dc\_user\_idx",  
> "shard" : 0,  
> "status" : 500,  
> "reason" : "No active shards"  
> }, {  
> "index" : "dc\_user\_idx",  
> "shard" : 3,  
> "status" : 500,  
> "reason" : "No active shards"  
> }, {  
> "index" : "dc\_user\_idx",  
> "shard" : 4,  
> "status" : 500,  
> "reason" : "No active shards"  
> } ]  
> },  
> "hits" : {  
> "total" : 0,  
> "max\_score" : null,  
> "hits" :   
> }  
> }  
> how to resolve this problem..
> 
> On Tuesday, March 12, 2013 11:47:00 AM UTC+5:30, srikanth gone wrote:
> 
> > 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) 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)[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 à 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).  
> > > 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).

---

<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 12, 2013, 10:31am UTC](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092/24 "2013-03-12T10:31:25Z")

</div>

Use queryString: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/query-string-query.html)  
It will search by default in the default \_all field.

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

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

> Hi David,
> 
> Thanks you very much.. its working fine.. i have configured new Elasticsearch..
> 
> how to search text without specifying fieldName.. which method is better.. can you suggest me..
> 
> On Tuesday, March 12, 2013 2:46:32 PM UTC+5:30, David Pilato wrote:  
> Ok. Follow theses steps:
> 
> curl -XDELETE [http://localhost:9200/](http://localhost:9200/)
> 
> curl -XPUT '[http://localhost:9200/dc\_user\_idx](http://localhost:9200/dc_user_idx)' -d '{  
> "settings" : {  
> "index" : {  
> "number\_of\_shards" : 1,  
> "number\_of\_replicas" : 0  
> }  
> }  
> }'
> 
> 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"  
> }  
> }
> 
> curl '[http://localhost:9200/\_cluster/health?pretty=true](http://localhost:9200/_cluster/health?pretty=true)'
> 
> Your cluster should be "status":"green" (or at least yellow - due to the river).  
> If not yellow or green, try to have a clean and fresh installation of your elasticsearch.
> 
> One more question: are you running more than one node?
> 
> --  
> David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
> @dadoonet | @elasticsearchfr | @scrutmydocs
> 
> Le 12 mars 2013 à 08:07, srikanth gone [srika...@gmail.com](mailto:srika...@gmail.com) a écrit :
> 
> > hi David, i have cleaned mongo Database and elastic server data folder..
> > 
> > and restarted server.. created 5 records in DC\_USER table..
> > 
> > SearchResponse response = client.prepareSearch().setQuery(QueryBuilders.textQuery("firstName", "admin")).setIndices("dc\_user\_idx").setTypes("DC\_USER").execute().actionGet();
> > 
> > when i call this query its not fetching data..
> > 
> > the output is:
> > 
> > {  
> > "took" : 47,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 2,  
> > "failed" : 3,  
> > "failures" : [ {  
> > "index" : "dc\_user\_idx",  
> > "shard" : 0,  
> > "status" : 500,  
> > "reason" : "No active shards"  
> > }, {  
> > "index" : "dc\_user\_idx",  
> > "shard" : 3,  
> > "status" : 500,  
> > "reason" : "No active shards"  
> > }, {  
> > "index" : "dc\_user\_idx",  
> > "shard" : 4,  
> > "status" : 500,  
> > "reason" : "No active shards"  
> > } ]  
> > },  
> > "hits" : {  
> > "total" : 0,  
> > "max\_score" : null,  
> > "hits" :   
> > }  
> > }  
> > how to resolve this problem..
> > 
> > On Tuesday, March 12, 2013 11:47:00 AM UTC+5:30, srikanth gone wrote:  
> > 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) 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 [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).  
> > 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, 10:38am UTC](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092/25 "2013-03-12T10:38:10Z")

</div>

thank you David..

for example if i have 2 users SampleUser, SampleUser1..  
if i send text as Sample, is it fetching data? or can i provide Sample\* ?

On Tuesday, March 12, 2013 4:01:25 PM UTC+5:30, David Pilato wrote:

> Use queryString:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/query-string-query.html)  
> It will search by default in the default \_all field.
> 
> --  
> _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 12 mars 2013 à 11:29, srikanth gone \<[srika...@gmail.com](mailto:srika...@gmail.com) \<javascript:\>\>  
> a écrit :
> 
> Hi David,
> 
> Thanks you very much.. its working fine.. i have configured new elastic  
> search..
> 
> how to search text without specifying fieldName.. which method is  
> better.. can you suggest me..
> 
> On Tuesday, March 12, 2013 2:46:32 PM UTC+5:30, David Pilato wrote:
> 
> > Ok. Follow theses steps:
> > 
> > curl -XDELETE [http://localhost:9200/](http://localhost:9200/)
> > 
> > curl -XPUT '[http://localhost:9200/dc\_user\_idx](http://localhost:9200/dc_user_idx)' -d '{  
> > "settings" : {  
> > "index" : {  
> > "number\_of\_shards" : 1,  
> > "number\_of\_replicas" : 0  
> > }  
> > }  
> > }'
> > 
> > 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"  
> > }  
> > }
> > 
> > curl '[http://localhost:9200/\_cluster/health?pretty=true](http://localhost:9200/_cluster/health?pretty=true)'
> > 
> > Your cluster should be "status":"green" (or at least yellow - due to the  
> > river).  
> > If not yellow or green, try to have a clean and fresh installation of  
> > your elasticsearch.
> > 
> > One more question: are you running more than one node?
> > 
> > --  
> > _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 12 mars 2013 à 08:07, srikanth gone [srika...@gmail.com](mailto:srika...@gmail.com) a écrit :
> > 
> > hi David, i have cleaned mongo Database and elastic server data folder..
> > 
> > and restarted server.. created 5 records in DC\_USER table..
> > 
> > SearchResponse response =  
> > client.prepareSearch().setQuery(QueryBuilders.textQuery("firstName",  
> > "admin")).setIndices("dc\_user\_idx").setTypes("DC\_USER").execute().actionGet();
> > 
> > when i call this query its not fetching data..
> > 
> > the output is:
> > 
> > {  
> > "took" : 47,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 2,  
> > "failed" : 3,  
> > "failures" : [ {  
> > "index" : "dc\_user\_idx",  
> > "shard" : 0,  
> > "status" : 500,  
> > "reason" : "No active shards"  
> > }, {  
> > "index" : "dc\_user\_idx",  
> > "shard" : 3,  
> > "status" : 500,  
> > "reason" : "No active shards"  
> > }, {  
> > "index" : "dc\_user\_idx",  
> > "shard" : 4,  
> > "status" : 500,  
> > "reason" : "No active shards"  
> > } ]  
> > },  
> > "hits" : {  
> > "total" : 0,  
> > "max\_score" : null,  
> > "hits" :   
> > }  
> > }  
> > how to resolve this problem..
> > 
> > On Tuesday, March 12, 2013 11:47:00 AM UTC+5:30, srikanth gone wrote:
> > 
> > > 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) 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)[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 à 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).  
> > > > 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).  
> > 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).

---

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

</div>

Now you have everything running to start to play with Elasticsearch.

I suggest that you read the documentation about queries ([Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/)) and so on, that you look at some videos ([Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/videos/))…  
Also, have a look at some old slides here: [Elasticsearch - Devoxx France 2012 - English version | KEY](http://fr.slideshare.net/dadoonet/elasticsearch-devoxx-france-2012-english-version)

Then, when you have questions (query that does not give the expected results for example), follow instructions on that page: [Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/help/)  
And please open a new Thread with your concrete problem.

About Java, you can find some documentation here: [Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/guide/reference/java-api/)

## HTH

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

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

> thank you David..
> 
> for example if i have 2 users SampleUser, SampleUser1..  
> if i send text as Sample, is it fetching data? or can i provide Sample\* ?
> 
> On Tuesday, March 12, 2013 4:01:25 PM UTC+5:30, David Pilato wrote:  
> Use queryString: [Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/query-string-query.html)  
> It will search by default in the default \_all field.
> 
> --  
> David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
> @dadoonet | @elasticsearchfr | @scrutmydocs
> 
> Le 12 mars 2013 à 11:29, srikanth gone [srika...@gmail.com](mailto:srika...@gmail.com) a écrit :
> 
> > Hi David,
> > 
> > Thanks you very much.. its working fine.. i have configured new Elasticsearch..
> > 
> > how to search text without specifying fieldName.. which method is better.. can you suggest me..
> > 
> > On Tuesday, March 12, 2013 2:46:32 PM UTC+5:30, David Pilato wrote:  
> > Ok. Follow theses steps:
> > 
> > curl -XDELETE [http://localhost:9200/](http://localhost:9200/)
> > 
> > curl -XPUT '[http://localhost:9200/dc\_user\_idx](http://localhost:9200/dc_user_idx)' -d '{  
> > "settings" : {  
> > "index" : {  
> > "number\_of\_shards" : 1,  
> > "number\_of\_replicas" : 0  
> > }  
> > }  
> > }'
> > 
> > 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"  
> > }  
> > }
> > 
> > curl '[http://localhost:9200/\_cluster/health?pretty=true](http://localhost:9200/_cluster/health?pretty=true)'
> > 
> > Your cluster should be "status":"green" (or at least yellow - due to the river).  
> > If not yellow or green, try to have a clean and fresh installation of your elasticsearch.
> > 
> > One more question: are you running more than one node?
> > 
> > --  
> > David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
> > @dadoonet | @elasticsearchfr | @scrutmydocs
> > 
> > Le 12 mars 2013 à 08:07, srikanth gone [srika...@gmail.com](mailto:srika...@gmail.com) a écrit :
> > 
> > > hi David, i have cleaned mongo Database and elastic server data folder..
> > > 
> > > and restarted server.. created 5 records in DC\_USER table..
> > > 
> > > SearchResponse response = client.prepareSearch().setQuery(QueryBuilders.textQuery("firstName", "admin")).setIndices("dc\_user\_idx").setTypes("DC\_USER").execute().actionGet();
> > > 
> > > when i call this query its not fetching data..
> > > 
> > > the output is:
> > > 
> > > {  
> > > "took" : 47,  
> > > "timed\_out" : false,  
> > > "\_shards" : {  
> > > "total" : 5,  
> > > "successful" : 2,  
> > > "failed" : 3,  
> > > "failures" : [ {  
> > > "index" : "dc\_user\_idx",  
> > > "shard" : 0,  
> > > "status" : 500,  
> > > "reason" : "No active shards"  
> > > }, {  
> > > "index" : "dc\_user\_idx",  
> > > "shard" : 3,  
> > > "status" : 500,  
> > > "reason" : "No active shards"  
> > > }, {  
> > > "index" : "dc\_user\_idx",  
> > > "shard" : 4,  
> > > "status" : 500,  
> > > "reason" : "No active shards"  
> > > } ]  
> > > },  
> > > "hits" : {  
> > > "total" : 0,  
> > > "max\_score" : null,  
> > > "hits" :   
> > > }  
> > > }  
> > > how to resolve this problem..
> > > 
> > > On Tuesday, March 12, 2013 11:47:00 AM UTC+5:30, srikanth gone wrote:  
> > > 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) 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 [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).  
> > > 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).  
> > 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:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:46am UTC](https://discuss.elastic.co/t/how-to-search-text-using-java-elastic-search/11092/27 "2017-07-06T02:46:59Z")

</div>



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