1 from copy import deepcopy as dc
3 # Template for search source format
4 SEARCH_SOURCE_FORMAT = {
7 "query": {"language": "lucene", "query": ""},
10 # Template for filter format
13 "match": {"placeholder_field": {"query": "query_phrase", "type": "phrase"}}
18 def generate(dash_config, viz_config, index_pattern):
20 search_source = dc(SEARCH_SOURCE_FORMAT)
22 # Search for 'match-with' and 'field' for each keys in 'filter' either
23 # in viz_config or dash_config
31 filters = dash_config["filter"]
32 for _, value in filters.items():
34 temp = dc(FILTER_FORMAT)
35 temp["query"]["match"][value["field"]] = temp["query"]["match"][
38 temp["query"]["match"][value["field"]]["query"] = value["match-with"]
39 del temp["query"]["match"]["placeholder_field"]
40 search_source["filter"].append(temp)
47 filters = viz_config["filter"]
48 for _, value in filters.items():
50 temp = dc(FILTER_FORMAT)
51 temp["query"]["match"][value["field"]] = temp["query"]["match"][
54 temp["query"]["match"][value["field"]]["query"] = value["match-with"]
55 del temp["query"]["match"]["placeholder_field"]
56 search_source["filter"].append(temp)
62 search_source["index"] = index_pattern