Class SearchResponse.Clusters

java.lang.Object
org.elasticsearch.action.search.SearchResponse.Clusters
All Implemented Interfaces:
Writeable, ToXContent, ToXContentFragment
Enclosing class:
SearchResponse

public static final class SearchResponse.Clusters extends Object implements ToXContentFragment, Writeable
Holds info about the clusters that the search was executed on: how many in total, how many of them were successful and how many of them were skipped and further details in a Map of Cluster objects (when doing a cross-cluster search).
  • Field Details

    • EMPTY

      public static final SearchResponse.Clusters EMPTY
    • _CLUSTERS_FIELD

      public static final ParseField _CLUSTERS_FIELD
    • TOTAL_FIELD

      public static final ParseField TOTAL_FIELD
    • SUCCESSFUL_FIELD

      public static final ParseField SUCCESSFUL_FIELD
    • SKIPPED_FIELD

      public static final ParseField SKIPPED_FIELD
    • RUNNING_FIELD

      public static final ParseField RUNNING_FIELD
    • PARTIAL_FIELD

      public static final ParseField PARTIAL_FIELD
    • FAILED_FIELD

      public static final ParseField FAILED_FIELD
    • DETAILS_FIELD

      public static final ParseField DETAILS_FIELD
  • Constructor Details

    • Clusters

      public Clusters(@Nullable OriginalIndices localIndices, Map<String,OriginalIndices> remoteClusterIndices, boolean ccsMinimizeRoundtrips, Predicate<String> skipUnavailablePredicate)
      For use with cross-cluster searches. When minimizing roundtrips, the number of successful, skipped, running, partial and failed clusters is not known until the end of the search and it the information in SearchResponse.Cluster object will be updated as each cluster returns.
      Parameters:
      localIndices - The localIndices to be searched - null if no local indices are to be searched
      remoteClusterIndices - mapping of clusterAlias -> OriginalIndices for each remote cluster
      ccsMinimizeRoundtrips - whether minimizing roundtrips for the CCS
      skipUnavailablePredicate - given a cluster alias, returns true if that cluster is skip_unavailable=true and false otherwise
    • Clusters

      public Clusters(int total, int successful, int skipped)
      Used for searches that are either not cross-cluster. For CCS minimize_roundtrips=true use Clusters(OriginalIndices, Map<String, OriginalIndices>, boolean)
      Parameters:
      total - total number of clusters in the search
      successful - number of successful clusters in the search
      skipped - number of skipped clusters (skipped can only happen for remote clusters with skip_unavailable=true)
    • Clusters

      public Clusters(StreamInput in) throws IOException
      Throws:
      IOException
    • Clusters

      public Clusters(Map<String,SearchResponse.Cluster> clusterInfoMap)
  • Method Details

    • writeTo

      public void writeTo(StreamOutput out) throws IOException
      Description copied from interface: Writeable
      Write this into the StreamOutput.
      Specified by:
      writeTo in interface Writeable
      Throws:
      IOException
    • toXContent

      public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException
      Specified by:
      toXContent in interface ToXContent
      Throws:
      IOException
    • getTotal

      public int getTotal()
      Returns:
      how many total clusters the search was requested to be executed on
    • getClusterStateCount

      public int getClusterStateCount(SearchResponse.Cluster.Status status)
      Parameters:
      status - the state you want to query
      Returns:
      how many clusters are currently in a specific state
    • isCcsMinimizeRoundtrips

      public Boolean isCcsMinimizeRoundtrips()
      Returns:
      whether this search was a cross cluster search done with ccsMinimizeRoundtrips=true
    • getCluster

      public SearchResponse.Cluster getCluster(String clusterAlias)
      Parameters:
      clusterAlias - The cluster alias as specified in the cluster collection
      Returns:
      Cluster object associated with teh clusterAlias or null if not present
    • swapCluster

      public SearchResponse.Cluster swapCluster(String clusterAlias, BiFunction<String,SearchResponse.Cluster,SearchResponse.Cluster> remappingFunction)
      Utility to swap a Cluster object. Guidelines for the remapping function:
      • The remapping function should return a new Cluster object to swap it for the existing one.
      • If in the remapping function you decide to abort the swap you must return the original Cluster object to keep the map unchanged.
      • Do not return null. If the remapping function returns null, the mapping is removed (or remains absent if initially absent).
      • If the remapping function itself throws an (unchecked) exception, the exception is rethrown, and the current mapping is left unchanged. Throwing exception therefore is OK, but it is generally discouraged.
      • The remapping function may be called multiple times in a CAS fashion underneath, make sure that is safe to do so.
      Parameters:
      clusterAlias - key with which the specified value is associated
      remappingFunction - function to swap the oldCluster to a newCluster
      Returns:
      the new Cluster object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hasPartialResults

      public boolean hasPartialResults()
      Returns:
      true if any underlying Cluster objects have PARTIAL, SKIPPED, FAILED or RUNNING status. or any Cluster is marked as timedOut.
    • hasClusterObjects

      public boolean hasClusterObjects()
      Returns:
      true if this Clusters object was initialized with underlying Cluster objects for tracking search Cluster details.
    • hasRemoteClusters

      public boolean hasRemoteClusters()
      Returns:
      true if this Clusters object has been initialized with remote Cluster objects This will be false for local-cluster (non-CCS) only searches.