How to do it...

The HTTP method that's used for both operations is POST. The URL format for flushing an index is as follows:

http://<server>/<index_name(s)>/_flush[?refresh=True]

The URL format for flushing all the indices in a cluster is as follows:

http:///_flush[?refresh=True]

  1. For flushing an index, we will perform the following steps: if we consider the type order of the previous chapter, the call will be as follows:
POST /myindex/_flush
  1. If everything is fine, the result returned by Elasticsearch should be as follows:
{
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
}
}

The result contains the shard operation status.