Transform this mysql query to elastic search
<p>I need to transform this mysql query to elastic search : </p>

<pre><code>select title, id, slug, is_cinema, release_date
        from media
        where media.is_active = 1
        AND media_type_id IN (1,3)
        and CASE media.media_type_id WHEN 1 THEN is_home = 1 ELSE is_home = 0 END
        and MATCH(title) AGAINST("*foo bar*" IN BOOLEAN MODE)
        ORDER by is_cinema DESC, CASE WHEN title LIKE "foo bar%" THEN 0 ELSE 1 END ASC, CASE media.media_type_id WHEN 3 THEN 0 when 1 then 1 ELSE 3 end ASC, release_date DESC limit 10;
</code></pre>

<p>I've done this as below and i get the results for the search. But i need to add this <code>"CASE media.media_type_id WHEN 1 THEN is_home = 1 ELSE is_home = 0 END"</code>and order by the exact match to the top <code>"ORDER by is_cinema DESC, CASE WHEN title LIKE "foo bar%" THEN 0 ELSE 1 END ASC, CASE media.media_type_id WHEN 3 THEN 0 when 1 then 1 ELSE 3 end ASC, release_date DESC limit 10"</code>. I've used prefix but it doesn't work for me as well.</p>

<p>Here is the elasticsearch query i've used :</p>

<pre><code>GET default/media/_search?pretty
{
    "query":{
      "filtered": {
         "query": {
            "bool": {
              "should": [
                 {
                     "match": {
                        "title": {
                            "query": "foo bar",
                            "boost": 2
                        }
                    }
                 },
                 {
                     "match_phrase": {
                        "title": {
                            "query": "foo bar",
                            "boost": 3
                        }
                    }
                 }
              ]
            }
         },
         "filter": {
             "bool": {
                 "must": [
                     {
                        "term":{
                        "is_active":1
                     }
                    },
                    {
                        "bool": {
                            "should": [
                                    {
                                       "term":{
                                            "media_type_id":1
                                        }
                                    },
                                    {
                                        "term":{
                                         "media_type_id":3
                                    }
                                }
                            ]
                        }
                    }
                  ]
             }
         }
      }
   }
</code></pre>