# Elasticsearch Spring JSONObject\[“hits”\] not found

**URL:** <https://discuss.elastic.co/t/elasticsearch-spring-jsonobject-hits-not-found/242503>\
**Category:** Elasticsearch\
**Created:** [July 24, 2020, 11:26am UTC](https://discuss.elastic.co/t/elasticsearch-spring-jsonobject-hits-not-found/242503 "2020-07-24T11:26:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tosunkaya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tosunkaya/32/72602_2.png) [@tosunkaya](https://discuss.elastic.co/u/tosunkaya)\
**Post date:** [July 24, 2020, 11:26am UTC](https://discuss.elastic.co/t/elasticsearch-spring-jsonobject-hits-not-found/242503/1 "2020-07-24T11:26:29Z")

</div>

I'm trying to do full text query search on if i GET [http://localhost:8080/search/query/tes](http://localhost:8080/search/query/tes) it should show users include tes in first or last name. i implemented them. but something is wrong, it says hits not found (JSONObject["hits"] not found). Spring Boot with Elasticsearch

 ![](https://us1.discourse-cdn.com/elastic/original/3X/7/1/71a85555137bae36f3624b0fad2e05c9d056a63b.png)  
 ![](https://us1.discourse-cdn.com/elastic/original/3X/1/6/16b1b361f1d65efa9f20682a914d8b8436aeff31.png)  
 ![](https://us1.discourse-cdn.com/elastic/original/3X/b/e/be9ee52cfadc197998b60dc61e83af05131ecf55.png)  
 ![](https://us1.discourse-cdn.com/elastic/original/3X/0/3/03966bcd51f32f5795e6b45b2a6f2df0caaf0708.png)  
 ![](https://us1.discourse-cdn.com/elastic/original/3X/2/5/250a796aa95b20f6bf2a83986ef756098877329c.png)

`  
@Service  
public class SearchService implements ISearchService {

@Value("${api.elasticsearch.uri}")  
private String elasticSearchUri;

@Value("${api.elasticsearch.search}")  
private String elasticSearchSearchPrefix;

private static final Logger LOGGER = LoggerFactory.getLogger(SearchService.class);

@Override  
public ResultQuery searchFromQuery(String query) throws IOException {  
String body = HelperFunctions.buildMultiIndexMatchBody(query);  
return executeHttpRequest(body);  
}

/\*\*

- Fetch resultQuery from elastic engine for the given body

- 
- @param body String

- @return ResultQuery

- @throws IOException IOException  
\*/  
private ResultQuery executeHttpRequest(String body) throws IOException{  
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {  
ResultQuery resultQuery = new ResultQuery();  
HttpPost httpPost = new HttpPost(HelperFunctions.buildSearchUri(elasticSearchUri  
, "", elasticSearchSearchPrefix));  
httpPost.setHeader(Accept, application/json);  
httpPost.setHeader(Content-type, application/json);  
try {  
httpPost.setEntity(new StringEntity(body, UTF-8));  
HttpResponse response = httpClient.execute(httpPost);  
String message = EntityUtils.toString(response.getEntity());  
JSONObject myObject = new JSONObject(message);  
if(myObject.getJSONObject(hits)  
.getInt(total) != 0){  
resultQuery  
.setElements(myObject  
.getJSONObject(hits)  
.getJSONArray(hits)  
.toString());  
resultQuery  
.setNumberOfResults(myObject.getJSONObject(hits)  
.getInt(total));  
resultQuery.setTimeTook((float) ((double) myObject.getInt(took) / 1000));  
} else {  
resultQuery.setElements(null);  
resultQuery.setNumberOfResults(0);  
resultQuery.setTimeTook((float) ((double) myObject.getInt(took) / 1000));  
}  
} catch (IOException | JSONException e) {  
LOGGER.error("Error while connecting to elastic engine --\> {}", e.getMessage());  
resultQuery.setNumberOfResults(0);  
}

}  
`

---

<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:** [August 21, 2020, 11:26am UTC](https://discuss.elastic.co/t/elasticsearch-spring-jsonobject-hits-not-found/242503/2 "2020-08-21T11:26:32Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
