forked from elastic/rally-tracks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
track.py
98 lines (82 loc) · 3.1 KB
/
track.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import os
import random
class QueryParamSource:
# We need to stick to the param source API
# noinspection PyUnusedLocal
def __init__(self, track, params, **kwargs):
self._params = params
self.infinite = True
cwd = os.path.dirname(__file__)
# The terms.txt file has been generated with:
# sed -n '13~250p' [path_to_rally_data]/geonames/documents.json | shuf | sed -e "s/.*name\": \"//;s/\",.*$//" > terms.txt
with open(os.path.join(cwd, "terms.txt"), "r") as ins:
self.terms = [line.strip() for line in ins.readlines()]
# We need to stick to the param source API
# noinspection PyUnusedLocal
def partition(self, partition_index, total_partitions):
return self
class PureTermsQueryParamSource(QueryParamSource):
def params(self):
query_terms = list(self.terms) # copy
query_terms.append(str(random.randint(1, 100))) # avoid caching
result = {
"body": {
"query": {
"terms": {"name.raw": query_terms},
}
},
"index": None,
}
if "cache" in self._params:
result["cache"] = self._params["cache"]
return result
class FilteredTermsQueryParamSource(QueryParamSource):
def params(self):
query_terms = list(self.terms) # copy
query_terms.append(str(random.randint(1, 1000))) # avoid caching
result = {
"body": {
"query": {
"bool": {
"must": [
{"match": {"feature_class.raw": "T"}},
],
"filter": [
{"terms": {"name.raw": query_terms}},
],
}
}
},
"index": None,
}
if "cache" in self._params:
result["cache"] = self._params["cache"]
return result
class ProhibitedTermsQueryParamSource(QueryParamSource):
def params(self):
query_terms = list(self.terms) # copy
query_terms.append(str(random.randint(1, 1000))) # avoid caching
result = {
"body": {
"query": {
"bool": {
"must": [
{"match": {"feature_class.raw": "A"}},
],
"must_not": [
{"terms": {"name.raw": query_terms}},
],
}
}
},
"index": None,
}
if "cache" in self._params:
result["cache"] = self._params["cache"]
return result
def refresh(es, params):
es.indices.refresh(index=params.get("index", "_all"))
def register(registry):
registry.register_param_source("pure-terms-query-source", PureTermsQueryParamSource)
registry.register_param_source("filtered-terms-query-source", FilteredTermsQueryParamSource)
registry.register_param_source("prohibited-terms-query-source", ProhibitedTermsQueryParamSource)