]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: es: limit indexing to only configured user meta
authorYehuda Sadeh <yehuda@redhat.com>
Fri, 31 Mar 2017 00:11:02 +0000 (17:11 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Tue, 30 May 2017 20:24:44 +0000 (13:24 -0700)
only metadata keys that are configured on user's bucket are allowed
to be indexed. Also, use the type of meta that was configured.

Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_sync_module_es.cc

index fd0df360cb547f349acdfe40aa564dac9968143a..b80f5ba1bbd78374d36c73ca985f08b9c9c19741 100644 (file)
@@ -8,6 +8,7 @@
 #include "rgw_rest_conn.h"
 #include "rgw_cr_rest.h"
 #include "rgw_op.h"
+#include "rgw_es_query.h"
 
 #define dout_subsys ceph_subsys_rgw
 
@@ -157,9 +158,51 @@ struct es_obj_metadata {
     for (auto i : out_attrs) {
       ::encode_json(i.first.c_str(), i.second, f);
     }
-    if (!custom_meta.empty()) {
+    map<string, string> custom_str;
+    map<string, string> custom_int;
+    map<string, string> custom_date;
+
+    for (auto i : custom_meta) {
+      auto config = bucket_info.mdsearch_config.find(i.first);
+      if (config == bucket_info.mdsearch_config.end()) {
+        ldout(cct, 20) << "custom meta entry key=" << i.first << " not found in bucket mdsearch config: " << bucket_info.mdsearch_config << dendl;
+        continue;
+      }
+      switch (config->second) {
+        case ESEntityTypeMap::ES_ENTITY_DATE:
+          custom_date[i.first] = i.second;
+          break;
+        case ESEntityTypeMap::ES_ENTITY_INT:
+          custom_int[i.first] = i.second;
+          break;
+        default:
+          custom_str[i.first] = i.second;
+      }
+    }
+
+    if (!custom_str.empty()) {
       f->open_array_section("custom-string");
-      for (auto i : custom_meta) {
+      for (auto i : custom_str) {
+        f->open_object_section("entity");
+        ::encode_json("name", i.first.c_str(), f);
+        ::encode_json("value", i.second, f);
+        f->close_section();
+      }
+      f->close_section();
+    }
+    if (!custom_int.empty()) {
+      f->open_array_section("custom-int");
+      for (auto i : custom_int) {
+        f->open_object_section("entity");
+        ::encode_json("name", i.first.c_str(), f);
+        ::encode_json("value", i.second, f);
+        f->close_section();
+      }
+      f->close_section();
+    }
+    if (!custom_date.empty()) {
+      f->open_array_section("custom-date");
+      for (auto i : custom_date) {
         f->open_object_section("entity");
         ::encode_json("name", i.first.c_str(), f);
         ::encode_json("value", i.second, f);