]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: es: also return custom int and date results
authorYehuda Sadeh <yehuda@redhat.com>
Fri, 31 Mar 2017 21:51:05 +0000 (14:51 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Tue, 30 May 2017 20:24:44 +0000 (13:24 -0700)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_sync_module_es.cc
src/rgw/rgw_sync_module_es_rest.cc

index b80f5ba1bbd78374d36c73ca985f08b9c9c19741..4927e2889fd289698571b8651ed42c7245bbf6b8 100644 (file)
@@ -30,16 +30,32 @@ static string es_get_obj_path(const RGWRealm& realm, const RGWBucketInfo& bucket
 }
 
 struct es_dump_type {
-  string type;
+  const char *type;
+  const char *format;
 
-  es_dump_type(const string& t) : type(t) {}
+  es_dump_type(const char *t, const char *f = nullptr) : type(t), format(f) {}
 
   void dump(Formatter *f) const {
     encode_json("type", type, f);
+    if (format) {
+      encode_json("format", format, f);
+    }
   }
 };
 
 struct es_index_mappings {
+  void dump_custom(Formatter *f, const char *section, const char *type, const char *format) const {
+    f->open_object_section(section);
+    ::encode_json("type", "nested", f);
+    f->open_object_section("properties");
+    f->open_object_section("name");
+    ::encode_json("type", "string", f);
+    ::encode_json("index", "not_analyzed", f);
+    f->close_section(); // name
+    encode_json("value", es_dump_type(type, format), f);
+    f->close_section(); // entry
+    f->close_section(); // custom-string
+  }
   void dump(Formatter *f) const {
     f->open_object_section("mappings");
     f->open_object_section("object");
@@ -61,16 +77,9 @@ struct es_index_mappings {
     ::encode_json("format", "strict_date_optional_time||epoch_millis", f);
     f->close_section(); // mtime
     encode_json("size", es_dump_type("long"), f);
-    f->open_object_section("custom-string");
-    ::encode_json("type", "nested", f);
-    f->open_object_section("properties");
-    f->open_object_section("name");
-    ::encode_json("type", "string", f);
-    ::encode_json("index", "not_analyzed", f);
-    f->close_section(); // name
-    encode_json("value", es_dump_type("string"), f);
-    f->close_section(); // entry
-    f->close_section(); // custom-string
+    dump_custom(f, "custom-string", "string", nullptr);
+    dump_custom(f, "custom-int", "long", nullptr);
+    dump_custom(f, "custom-date", "date", "strict_date_optional_time||epoch_millis");
     f->close_section(); // properties
     f->close_section(); // meta
     f->close_section(); // properties
index cc41c85f7ae4f2f9954555a758b39652577eac2b..8bd4cebd90c2e1a73f91014e87f07c92f4d375c8 100644 (file)
@@ -19,6 +19,8 @@ struct es_index_obj_response {
     ceph::real_time mtime;
     string etag;
     map<string, string> custom_str;
+    map<string, int64_t> custom_int;
+    map<string, string> custom_date;
 
     template <class T>
     struct _custom_entry {
@@ -41,6 +43,16 @@ struct es_index_obj_response {
       for (auto& e : str_entries) {
         custom_str[e.name] = e.value;
       }
+      list<_custom_entry<int64_t> > int_entries;
+      JSONDecoder::decode_json("custom-int", int_entries, obj);
+      for (auto& e : int_entries) {
+        custom_int[e.name] = e.value;
+      }
+      list<_custom_entry<string> > date_entries;
+      JSONDecoder::decode_json("custom-date", date_entries, obj);
+      for (auto& e : date_entries) {
+        custom_date[e.name] = e.value;
+      }
     }
   } meta;
 
@@ -304,6 +316,18 @@ public:
         s->formatter->dump_string("Value", m.second);
         s->formatter->close_section();
       }
+      for (auto& m : e.meta.custom_int) {
+        s->formatter->open_object_section("Entry");
+        s->formatter->dump_string("Name", m.first.c_str());
+        s->formatter->dump_int("Value", m.second);
+        s->formatter->close_section();
+      }
+      for (auto& m : e.meta.custom_date) {
+        s->formatter->open_object_section("Entry");
+        s->formatter->dump_string("Name", m.first.c_str());
+        s->formatter->dump_string("Value", m.second);
+        s->formatter->close_section();
+      }
       s->formatter->close_section();
       s->formatter->close_section();
       rgw_flush_formatter(s, s->formatter);