]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: es: support for ES 5.0+
authorAbhishek Lekshmanan <abhishek@suse.com>
Mon, 7 May 2018 13:04:40 +0000 (15:04 +0200)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 25 Jan 2019 23:45:57 +0000 (15:45 -0800)
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 <abhishek@suse.com>
src/rgw/rgw_sync_module_es.cc

index db64662c77fe344820bf9c7ad2f4c2bf4da2db05..d98190e4bfe7119b7168a9e9f70579170e924419 100644 (file)
@@ -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<ESInfo> (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<es_index_config, int>(sync_env->cct, conf->conn.get(),
-                                                              sync_env->http_manager,
-                                                              path, nullptr /* params */,
-                                                              index_conf, nullptr /* result */));
+        std::map <string, string> hdrs = {{ "Content-Type", "application/json" }};
+        call(new RGWPutRESTResourceCR<es_index_config, int> (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 <string, string> hdrs = {{ "Content-Type", "application/json" }};
         call(new RGWPutRESTResourceCR<es_obj_metadata, int>(sync_env->cct, conf->conn.get(),
                                                             sync_env->http_manager,
                                                             path, nullptr /* params */,
+                                                            &hdrs,
                                                             doc, nullptr /* result */));
 
       }