1 from copy import deepcopy as dc
3 # Template for search source format
4 SEARCH_SOURCE_FORMAT = {"index": None, "filter": [],
5 "query": {"language": "lucene", "query": ""}}
7 # Template for filter format
11 "placeholder_field": {
12 "query": "query_phrase",
20 def generate(dash_config, viz_config, index_pattern):
22 search_source = dc(SEARCH_SOURCE_FORMAT)
24 # Search for 'match-with' and 'field' for each keys in 'filter' either
25 # in viz_config or dash_config
33 filters = dash_config['filter']
34 for _, value in filters.items():
36 temp = dc(FILTER_FORMAT)
37 temp['query']['match'][value['field']
39 temp['query']['match']['placeholder_field']
40 temp['query']['match'][value['field']
41 ]['query'] = value['match-with']
42 del temp['query']['match']['placeholder_field']
43 search_source['filter'].append(temp)
50 filters = viz_config['filter']
51 for _, value in filters.items():
53 temp = dc(FILTER_FORMAT)
54 temp['query']['match'][value['field']
56 temp['query']['match']['placeholder_field']
57 temp['query']['match'][value['field']
58 ]['query'] = value['match-with']
59 del temp['query']['match']['placeholder_field']
60 search_source['filter'].append(temp)
66 search_source['index'] = index_pattern