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