Hi all,
we will store searchable data into the _source field. So there isn't stored
a classic known document like pdf or so. Additionally we will store the
database primary key in the _scource field like this:
_source{ "searchfield1":"value1","searchfield2":"value2","dbkey":"4711"}
If we'll get the dbkeys from ES search by a query to process some other
stuff, is it the preferred method to do the following process:
- send a CountRequest to get the "count" of the searchquery,
- after this send a SearchRequest with the same query and with
SearchType.SCAN and setSize(count) to receive the ids, - then send a GetRequest in a id based for-loop to get all documents
(_source fields) to receive the dbkey field
I think there must be another approach. Can you help me?
some code for better understanding:
....
CountResponse countResp = esClient.prepareCount(index).setTypes(types)
.setQuery(QueryBuilders.queryString(luceneNativeQuery)).execute().actionGet();
int total = ((Long) countResp.getCount()).intValue();
SearchResponse searchResponse =
esClient.prepareSearch(index).setTypes(types).setQuery(QueryBuilders.queryString(luceneNativeQuery)).setSize(total).setSearchType(SearchType.SCAN).execute().actionGet();
for (SearchHit hit : searchResponse.getHits().getHits()) {
GetRequest getRequest = new GetRequest(index, hit.getType(), hit.getId());
GetResponse getResponse = esClient.get(getRequest).actionGet();
if (!getResponse.getSource().isEmpty()) {
DataReference dataReference =
(DataReference) getResponse.getSource().get(DATA_REFERENCE);
searchResults.add(dataReference);
}
}
....
Best regards and many thanks in advance
Alex
--
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.
For more options, visit https://groups.google.com/groups/opt_out.