# How to get the searched items?

**URL:** <https://discuss.elastic.co/t/how-to-get-the-searched-items/3679>\
**Category:** Elasticsearch\
**Created:** [December 18, 2010, 2:31pm UTC](https://discuss.elastic.co/t/how-to-get-the-searched-items/3679 "2010-12-18T14:31:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cheepu](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@cheepu](https://discuss.elastic.co/u/cheepu)\
**Post date:** [December 18, 2010, 2:31pm UTC](https://discuss.elastic.co/t/how-to-get-the-searched-items/3679/1 "2010-12-18T14:31:58Z")

</div>

Hi  
I created a JSON Document as follows:

JSONArray jArray = new JArray();  
jArray.add("jhon");  
jArray.add("jerry");  
jArray.add("sam");

JSONObject jObject = new JSONObject();  
jObject.add("first",jArray);

For Searching I am writing following code:

SearchResponse searchResponse = client.prepareSearch("twitter")  
.setSearchType(SearchType.DEFAULT)  
.setQuery(wildcardQuery("first","j\*"))  
.setFrom(0).setSize(60).setExplain(true)  
.execute()  
.actionGet();  
SearchHits sh = searchResponse.getHits();  
System.out.println("Total Hits are sh.totalHits() : "+sh.hits().length);

I have not done any configuration what ever is default.  
My Problems are:

1. I am getting only 1 hit but it should give 2 because (as I understand) j\* will search jhon and jerry
2. How can i get the value of the hit( for eg if jhon is found then how can i get printed jhon)
3. If i make any change in the JSONObject and run the program the changes are not reflected in one time i need to run once again.

I have spent lots of time in finding the reasons for these but I could not get.  
Please help to resolve the problem  
May be title doesnot suite the problem, sorry for that

Thanks

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [December 22, 2010, 2:52pm UTC](https://discuss.elastic.co/t/how-to-get-the-searched-items/3679/2 "2010-12-22T14:52:14Z")

</div>

On Sat, Dec 18, 2010 at 4:31 PM, cheepu [cheeputech@gmail.com](mailto:cheeputech@gmail.com) wrote:

> Hi  
> I created a JSON Document as follows:
> 
> JSONArray jArray = new JArray();  
> jArray.add("jhon");  
> jArray.add("jerry");  
> jArray.add("sam");
> 
> JSONObject jObject = new JSONObject();  
> jObject.add("first",jArray);
> 
> For Searching I am writing following code:
> 
> SearchResponse searchResponse = client.prepareSearch("twitter")  
> .setSearchType(SearchType.DEFAULT)  
> .setQuery(wildcardQuery("first","j\*"))  
> .setFrom(0).setSize(60).setExplain(true)  
> .execute()  
> .actionGet();  
> SearchHits sh = searchResponse.getHits();  
> System.out.println("Total Hits are sh.totalHits() :  
> "+sh.hits().length);
> 
> I have not done any configuration what ever is default.  
> My Problems are:
> 
> 1. I am getting only 1 hit but it should give 2 because (as I understand)  
> j\*  
> will search jhon and jerry

Each document you index is a hit. You might want to index a document per  
name in this case.

> 1. How can i get the value of the hit( for eg if jhon is found then how can  
> i get printed jhon)

From the SearchHits, you can get a SearchHit, and then get back the actual  
raw bytes, or a parsed map (of maps) representing the json structure.

> 1. If i make any change in the JSONObject and run the program the changes  
> are not reflected in one time i need to run once again.

You need to reindex the data. If you want to update a document, make sure  
you use the same id. Note that search visibility is near real time, you can  
issue a refresh command (client.admin.indices.prepareRefresh) to make sure  
you search on what was indexed up to that point.

> I have spent lots of time in finding the reasons for these but I could not  
> get.  
> Please help to resolve the problem  
> May be title doesnot suite the problem, sorry for that
> 
> Thanks
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/How-to-get-the-searched-items-tp2111149p2111149.html](http://elasticsearch-users.115913.n3.nabble.com/How-to-get-the-searched-items-tp2111149p2111149.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<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, 4:14am UTC](https://discuss.elastic.co/t/how-to-get-the-searched-items/3679/3 "2017-07-06T04:14:59Z")

</div>

Closed on July 6, 2017, 4:14am UTC


