How to issue _optimize on Elastic Cloud

I am trying to issue an _optimize command via curl. I've tried both of the below styles:

$ curl --user username:password -XPOST "https://redacted.us-east-1.aws.found.io:9243/foo/_optimize?max_num_segments=1"
{"error":{"root_cause":[{"type":"parse_exception","reason":"request body is required"}],"type":"parse_exception","reason":"request 

$ curl --user username:password -H 'Content-Type: application/json' -XPOST https://redacted.us-east-1.aws.found.io:9243/foo/_optimize -d '{"max_num_segments" : "1"}'
{"error":{"root_cause":[{"type":"invalid_type_name_exception","reason":"Document mapping type name can't start with '_', found: [_optimize]"}],"type":"invalid_type_name_exception","reason":"Document mapping type name can't start with '_', found: [_optimize]"},"status":400}

Is _optimize supported on the Elastic Cloud version of Elasticsearch?

The _optimize endpoint was deprecated in Elasticsearch 2.1 and subsequently removed in Elasticsearch 5.0. It was replaced by _forcemerge which more accurately describes what it's doing. Replace _optimize with _forcemerge and if you want to read more, have a look at the force merge API documentation

1 Like

@shanec Is it still recommended to run _forcemerge on indexes that you know will no longer be added to, to set the # of segments to 1?

Elasticsearch will automatically merge segments in the background for you. If you want to explicitly do so at an optimal time, _forcemerge can be useful. But to be honest, most users don't need to explicitly call forcemerge.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.