public List query(){
List lineRange = new ArrayList();
Settings settings = Settings.settingsBuilder().put("cluster.name", "elasticsearch").build();
Client client = TransportClient.builder().settings(settings).build().addTransportAddress((TransportAddress) new InetSocketTransportAddress(new InetSocketAddress("127.0.0.1", 9300)));
SearchResponse sResponse = null;
QueryBuilder qb = QueryBuilders.rangeQuery("lineNumber").from(50).to(150);
sResponse = client.prepareSearch("jsonlogpage")
.setTypes("loglinenum")
.setQuery(qb)
.execute()
.actionGet();
for(SearchHit hit : sResponse.getHits()){
timeRange.add(hit); //add() shows error
}
i++;
}
return timeRange;
}
I'm using Search Response. I got an error in add().
Error: Exception in thread "main" java.lang.ClassCastException: org.elasticsearch.search.internal.InternalSearchHit cannot be cast to com.example.elasticsearch.LogLineEntry
LogLineEntry is a pojo class. My List is created for LogLineEntry, hit variable belongs to SearchHit. So I can't add searchHit variable into List. How can I resolve this?