def get_topic_threshold_query(model_run_info_id, topic_percentage):
    """
    model_run_info_id: id of the topic model
    topic_percentage: dict => {topic_id: percentage (0-1)}
    """

    topic_filters = [dict(range={f"topics.topic_{id}": {"gte": val}})
                     for id, val in sorted(topic_percentage.items())]

    query = dict(bool=dict(
        must=[{"term": {"model_run_info_id": model_run_info_id}}] + topic_filters))

    return query