]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_es_main.cc
import 15.2.0 Octopus source
[ceph.git] / ceph / src / rgw / rgw_es_main.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
3
4 #include <list>
5 #include <string>
6 #include <iostream>
7
8 #include "global/global_init.h"
9 #include "global/global_context.h"
10
11 #include "common/ceph_argparse.h"
12 #include "common/ceph_json.h"
13 #include "rgw_es_query.h"
14
15
16 int main(int argc, char *argv[])
17 {
18 vector<const char*> args;
19 argv_to_vec(argc, (const char **)argv, args);
20
21 auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
22 CODE_ENVIRONMENT_UTILITY, 0);
23
24 common_init_finish(g_ceph_context);
25
26 string expr;
27
28 if (argc > 1) {
29 expr = argv[1];
30 } else {
31 expr = "age >= 30";
32 }
33
34 ESQueryCompiler es_query(expr, nullptr, "x-amz-meta-");
35
36 map<string, string, ltstr_nocase> aliases = { { "key", "name" },
37 { "etag", "meta.etag" },
38 { "size", "meta.size" },
39 { "mtime", "meta.mtime" },
40 { "lastmodified", "meta.mtime" },
41 { "contenttype", "meta.contenttype" },
42 };
43 es_query.set_field_aliases(&aliases);
44
45 map<string, ESEntityTypeMap::EntityType> generic_map = { {"bucket", ESEntityTypeMap::ES_ENTITY_STR},
46 {"name", ESEntityTypeMap::ES_ENTITY_STR},
47 {"instance", ESEntityTypeMap::ES_ENTITY_STR},
48 {"meta.etag", ESEntityTypeMap::ES_ENTITY_STR},
49 {"meta.contenttype", ESEntityTypeMap::ES_ENTITY_STR},
50 {"meta.mtime", ESEntityTypeMap::ES_ENTITY_DATE},
51 {"meta.size", ESEntityTypeMap::ES_ENTITY_INT} };
52 ESEntityTypeMap gm(generic_map);
53 es_query.set_generic_type_map(&gm);
54
55 map<string, ESEntityTypeMap::EntityType> custom_map = { {"str", ESEntityTypeMap::ES_ENTITY_STR},
56 {"int", ESEntityTypeMap::ES_ENTITY_INT},
57 {"date", ESEntityTypeMap::ES_ENTITY_DATE} };
58 ESEntityTypeMap em(custom_map);
59 es_query.set_custom_type_map(&em);
60
61 string err;
62
63 bool valid = es_query.compile(&err);
64 if (!valid) {
65 cout << "failed to compile query: " << err << std::endl;
66 return EINVAL;
67 }
68
69 JSONFormatter f;
70 encode_json("root", es_query, &f);
71
72 f.flush(cout);
73
74 return 0;
75 }
76