I am querying elasticsearch with the below query
SearchResponse searchResponse = getElasticSearchClient()
.prepareSearch(indexNameStr).setTypes(typeNameStr)
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(queryStrr).setSize(size)
.setFrom(start).addSort(fieldSortBuilder)
.execute().actionGet();
I wanted to check if the search is success or failure. Catch exception If
there are any during search.
Is it correct to use below method to identify failures in search;
public void parseSearchResultFailures(SearchResponse res) {
if (res.getFailedShards() > 0) {
final ShardSearchFailure[] shardFailures =
res.getShardFailures();
StringBuilder reasonBuilder = new StringBuilder();
for (ShardSearchFailure failure : shardFailures) {
final String reason = failure.reason();
LOGGER.info("Status: " + failure.status()
+ " - Search failed on shard: " + reason);
reasonBuilder.append(reason);
}
throw new ElasticsearchException("Search failed: "
+ reasonBuilder.toString());
}
}
Thanks,
--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/check-searchresponse-is-success-or-failure-for-a-given-search-tp4068846.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/1421061184602-4068846.post%40n3.nabble.com.
For more options, visit https://groups.google.com/d/optout.