[
    // Default query template (Don't run)
    {
        "query": {
            "bool": {
                "must": ["filters"]
            }
        }
    },
    // visited = true
    {
        "query": {
            "bool": {
                "must": [{"term": {"has_visits": true}}]
            }
        }
    },
    // (((visited = true and visits > 0)))
    {
        "query": {
            "bool": {
                "must": [{
                    "bool": {
                        "must": [
                            {"term": {"has_visits": true}},
                            {"range": {"nb_visits": {"gt": 0}}}
                        ]
                    }
                }]
            }
        }
    },
    // origin : django and metadata : "web"
    {
        "query": {
            "bool": {
                "must": [{
                    "bool": {
                        "must": [
                            {
                                "multi_match": {
                                    "query": "django",
                                    "type": "bool_prefix",
                                    "operator": "and",
                                    "fields": [
                                        "url.as_you_type",
                                        "url.as_you_type._2gram",
                                        "url.as_you_type._3gram"
                                    ]
                                }
                            },
                            {
                                "nested": {
                                    "path": "intrinsic_metadata",
                                    "query": {
                                        "multi_match": {
                                            "query": "web",
                                            "type": "cross_fields",
                                            "operator": "and",
                                            "fields": ["intrinsic_metadata.*"],
                                            "lenient": true
                                        }
                                    }
                                }
                            }
                        ]
                    }
                }]
            }
        }
    },
    // origin : django
    {
        "query": {
            "bool": {
                "must": [{
                    "bool": {
                        "should": [
                            {
                                "multi_match": {
                                    "query": "django",
                                    "type": "bool_prefix",
                                    "operator": "and",
                                    "fields": [
                                        "url.as_you_type",
                                        "url.as_you_type._2gram",
                                        "url.as_you_type._3gram"
                                    ]
                                }
                            }
                        ]
                    }
                }]
            }
        }
    },
    // metadata : "web"
    {
        "query": {
            "bool": {
                "must": [{
                    "bool": {
                        "should": [
                            {
                                "nested": {
                                    "path": "intrinsic_metadata",
                                    "query": {
                                        "multi_match": {
                                            "query": "web",
                                            "type": "cross_fields",
                                            "operator": "and",
                                            "fields": ["intrinsic_metadata.*"],
                                            "lenient": true
                                        }
                                    }
                                }
                            }
                        ]
                    }
                }]
            }
        }
    },
    // origin : django or metadata : "web"
    {
        "query": {
            "bool": {
                "must": [{
                    "bool": {
                        "should": [
                            {
                                "multi_match": {
                                    "query": "django",
                                    "type": "bool_prefix",
                                    "operator": "and",
                                    "fields": [
                                        "url.as_you_type",
                                        "url.as_you_type._2gram",
                                        "url.as_you_type._3gram"
                                    ]
                                }
                            },
                            {
                                "nested": {
                                    "path": "intrinsic_metadata",
                                    "query": {
                                        "multi_match": {
                                            "query": "framework and web",
                                            "type": "cross_fields",
                                            "operator": "and",
                                            "fields": ["intrinsic_metadata.*"],
                                            "lenient": true
                                        }
                                    }
                                }
                            }
                        ]
                    }
                }]
            }
        }
    },
    // visits != 5
    {
        "query": {
            "bool": {
                "must": [{
                    "bool": {"must_not": [{"range": {"nb_visits": {"gte": 5, "lte": 5}}}]}
                }]
            }
        }
    },
    // visit_type = [git,"pypi"]
    {
        "query": {
            "bool": {
                "must": [
                    {"terms": {"visit_types": ["git", "pypi"]}}
                ]
            }
        }
    }
]