]>
Commit | Line | Data |
---|---|---|
11fdf7f2 | 1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
9f95a23c | 2 | // vim: ts=8 sw=2 smarttab ft=cpp |
11fdf7f2 | 3 | |
31f18b77 FG |
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 | ||
20effc67 | 15 | using namespace std; |
31f18b77 FG |
16 | |
17 | int main(int argc, char *argv[]) | |
18 | { | |
20effc67 | 19 | auto args = argv_to_vec(argc, argv); |
31f18b77 FG |
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 | ||
31f18b77 FG |
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 |