}
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");
::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
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 {
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;
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);