From 7b61c992b79afe3b70c544ce137b04b95532bacd Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Fri, 31 Mar 2017 14:51:05 -0700 Subject: [PATCH] rgw: es: also return custom int and date results Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_sync_module_es.cc | 33 +++++++++++++++++++----------- src/rgw/rgw_sync_module_es_rest.cc | 24 ++++++++++++++++++++++ 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/rgw/rgw_sync_module_es.cc b/src/rgw/rgw_sync_module_es.cc index b80f5ba1bbd78..4927e2889fd28 100644 --- a/src/rgw/rgw_sync_module_es.cc +++ b/src/rgw/rgw_sync_module_es.cc @@ -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 diff --git a/src/rgw/rgw_sync_module_es_rest.cc b/src/rgw/rgw_sync_module_es_rest.cc index cc41c85f7ae4f..8bd4cebd90c2e 100644 --- a/src/rgw/rgw_sync_module_es_rest.cc +++ b/src/rgw/rgw_sync_module_es_rest.cc @@ -19,6 +19,8 @@ struct es_index_obj_response { ceph::real_time mtime; string etag; map custom_str; + map custom_int; + map custom_date; template 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 > int_entries; + JSONDecoder::decode_json("custom-int", int_entries, obj); + for (auto& e : int_entries) { + custom_int[e.name] = e.value; + } + list<_custom_entry > 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); -- 2.39.5