From: Abhishek Lekshmanan Date: Mon, 7 May 2018 13:04:40 +0000 (+0200) Subject: rgw: es: support for ES 5.0+ X-Git-Tag: v14.1.0~210^2~13 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=67d3cbd430e97f113628b9503e3cf2fa3047ee16;p=ceph.git rgw: es: support for ES 5.0+ from Elasticsearch 5.0+ the type string is deprecated, while it is still allowed in 5.0, it returns a 400 error on 6.0 clusters as this type is fully removed. We now determine the es version while initializing the cluster from elasticsearch's default endpoint and use that to determine what string type to use. This way we support both 2.x and 5.x,6.x es versions as we default to string type for clusters < 5.0 Fixes: http://tracker.ceph.com/issues/22877 Signed-off-by: Abhishek Lekshmanan --- diff --git a/src/rgw/rgw_sync_module_es.cc b/src/rgw/rgw_sync_module_es.cc index db64662c77f..d98190e4bfe 100644 --- a/src/rgw/rgw_sync_module_es.cc +++ b/src/rgw/rgw_sync_module_es.cc @@ -556,6 +556,7 @@ struct es_obj_metadata { class RGWElasticInitConfigCBCR : public RGWCoroutine { RGWDataSyncEnv *sync_env; ElasticConfigRef conf; + ESInfo es_info; public: RGWElasticInitConfigCBCR(RGWDataSyncEnv *_sync_env, ElasticConfigRef _conf) : RGWCoroutine(_sync_env->cct), @@ -564,18 +565,33 @@ public: int operate() override { reenter(this) { ldout(sync_env->cct, 0) << ": init elasticsearch config zone=" << sync_env->source_zone << dendl; + yield call(new RGWReadRESTResourceCR (sync_env->cct, + conf->conn.get(), + sync_env->http_manager, + "/", nullptr, &es_info)); + if (retcode < 0) { + return set_cr_error(retcode); + } + yield { string path = conf->get_index_path(); + ldout(sync_env->cct, 5) << "got elastic version=" << es_info.version.to_str() << dendl; es_index_settings settings(conf->num_replicas, conf->num_shards); es_index_mappings mappings; + if (es_info.version >= ESVersion(5,0)) { + ldout(sync_env->cct, 0) << "elasticsearch: using text type for string index mappings " << dendl; + mappings.string_type = ESType::Text; + } es_index_config index_conf(settings, mappings); - - call(new RGWPutRESTResourceCR(sync_env->cct, conf->conn.get(), - sync_env->http_manager, - path, nullptr /* params */, - index_conf, nullptr /* result */)); + std::map hdrs = {{ "Content-Type", "application/json" }}; + call(new RGWPutRESTResourceCR (sync_env->cct, + conf->conn.get(), + sync_env->http_manager, + path, nullptr /*params*/, + &hdrs, + index_conf, nullptr)); } if (retcode < 0) { return set_cr_error(retcode); @@ -605,9 +621,11 @@ public: string path = conf->get_obj_path(bucket_info, key); es_obj_metadata doc(sync_env->cct, conf, bucket_info, key, mtime, size, attrs, versioned_epoch); + std::map hdrs = {{ "Content-Type", "application/json" }}; call(new RGWPutRESTResourceCR(sync_env->cct, conf->conn.get(), sync_env->http_manager, path, nullptr /* params */, + &hdrs, doc, nullptr /* result */)); }