def optimize(self, indices=None,<EOL>wait_for_merge=False,<EOL>max_num_segments=None,<EOL>only_expunge_deletes=False,<EOL>refresh=True,<EOL>flush=True):
path = self.conn._make_path(indices, (), '<STR_LIT>')<EOL>params = dict(<EOL>wait_for_merge=wait_for_merge,<EOL>only_expunge_deletes=only_expunge_deletes,<EOL>refresh=refresh,<EOL>flush=flush,<EOL>)<EOL>for k, v in params.items():<EOL><INDENT>params[k] = v and "<STR_LIT:true>" or "<STR_LIT:false>"<EOL><DEDENT>if max_num_segments is not None:<EOL><INDENT>params['<STR_LIT>'] = max_num_segments<EOL><DEDENT>return self.conn._send_request('<STR_LIT:POST>', path, params=params)<EOL>
Optimize one or more indices.
(See :ref:`es-guide-reference-api-admin-indices-optimize`)


:keyword indices: the list of indices to optimise.  If not supplied, all
                  default_indices are optimised.

:keyword wait_for_merge: If True, the operation will not return until the merge has been completed.
                         Defaults to False.

:keyword max_num_segments: The number of segments to optimize to. To fully optimize the index, set it to 1.
                           Defaults to half the number configured by the merge policy (which in turn defaults
                           to 10).


:keyword only_expunge_deletes: Should the optimize process only expunge segments with deletes in it.
                               In Lucene, a document is not deleted from a segment, just marked as deleted.
                               During a merge process of segments, a new segment is created that does have
                               those deletes.
                               This flag allow to only merge segments that have deletes. Defaults to false.

:keyword refresh: Should a refresh be performed after the optimize. Defaults to true.

:keyword flush: Should a flush be performed after the optimize. Defaults to true.