(search_result)
Raise an ESShardFailure if there are shard failures in an ES search result (JSON)

    and report to datadog.
    The commcare.es.partial_results metric counts 1 per ES request with any shard failure.
Raise an ESShardFailure if there are shard failures in an ES search result (JSON)
Raise an ESShardFailure if there are shard failures in an ES search result ( JSON )
def report_and_fail_on_shard_failures(search_result):
    """
    Raise an ESShardFailure if there are shard failures in an ES search result (JSON)

    and report to datadog.
    The commcare.es.partial_results metric counts 1 per ES request with any shard failure.
    """
    if not isinstance(search_result, dict):
        return

    if search_result.get('_shards', {}).get('failed'):
        metrics_counter('commcare.es.partial_results')
        # Example message:
        #   "_shards: {'successful': 4, 'failed': 1, 'total': 5}"
        raise ESShardFailure('_shards: {!r}'.format(search_result.get('_shards')))
def report_and_fail_on_shard_failures ( search_result ) : if not isinstance ( search_result , dict ) : return if search_result . get ( '_shards' , { } ) . get ( 'failed' ) : metrics_counter ( 'commcare.es.partial_results' ) # Example message: #   "_shards: {'successful': 4, 'failed': 1, 'total': 5}" raise ESShardFailure ( '_shards: {!r}' . format ( search_result . get ( '_shards' ) ) )