   defp build_query_template(q, size, from) do
     %{
       query: %{
-        bool: %{
-          must: %{
-            query_string: %{
-              query: q
+        script_score: %{
+          query: %{
+            bool: %{
+              must: %{
+                query_string: %{
+                  query: q
+                }
+              },
+              filter: [],
+              must_not: []
             }
           },
-          filter: [],
-          must_not: []
+          script: %{
+            source: "_score"
+          }
         }
       },
       size: size,

  end

  def set_readable_projects(query, readable_projects) do
    update_in(query.query.bool.filter, fn filter ->
      filter ++ [%{ terms: %{ project: readable_projects }}]
    end)
  end

  def add_filters(query, nil), do: query
  def add_filters(query, filters) do
    filter = Enum.map(filters, &build_terms_query/1)
    update_in(query.query.script_score.query.bool.filter, &(&1 ++ filter))
  end

  def add_must_not(query, nil), do: query
  def add_must_not(query, must_not) do
    must_not = Enum.map(must_not, &build_terms_query/1)
    update_in(query.query.script_score.query.bool.must_not, &(&1 ++ must_not))
  end

  def add_exists(query, nil), do: query
  def add_exists(query, exists) do
    exists_filter = Enum.map(exists, &build_exists_query/1)
    update_in(query.query.script_score.query.bool.filter, &(&1 ++ exists_filter))
  end

  def add_not_exists(query, nil), do: query
  def add_not_exists(query, not_exists) do
    exists_filter = Enum.map(not_exists, &build_exists_query/1)
    update_in(query.query.script_score.query.bool.must_not, &(&1 ++ exists_filter))
  end

  def only_fields(query, fields) do
