I used logstash to save my mysql table data into elasticsearch. Now i want to get data from elasticsearch using specific field. I can get data using id but i am not able to retrieve data using other fields.
I am using elasticsearch 5.6.12 and spring boot 2.0
searchcontroller.java
@GetMapping("/view/{id}")
public SearchResponse view(@PathVariable final String id) {
SearchResponse response = client.prepareSearch("user_detail").setTypes("user")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(QueryBuilders.termQuery("first_name", id)).setFrom(1).setSize(4)
.setExplain(true).execute().actionGet() ;
SearchHit[] results = response.getHits().getHits();
System.out.println("Current results: " + results.length);
for (SearchHit hit : results) {
System.out.println("------------------------------");
Map<String, Object> result = hit.getSource();
System.out.println(result);
}
return response;
}
I want to search using first_name but nothing is showing. what am i doing wrong here?