       size: 10,
       stored_fields: [],
       query: %{
-        bool: %{
-          must:     [],
-          should:   [],
-          filter:   [],
-          must_not: [
-            %{term: %{is_comment: true}},
-            %{term: %{is_hidden:  true}},
-            %{term: %{is_repost:  true}},
-          ]
+        function_score: %{
+          query: %{
+            bool: %{
+              must:     [],
+              should:   [],
+              filter:   [],
+              must_not: [
+                %{term: %{is_comment: true}},
+                %{term: %{is_hidden:  true}},
+                %{term: %{is_repost:  true}},
+              ]
+            }
+          },
+          functions: [],
+          score_mode: "sum",
+          boost_mode: "sum"
         }
       }
     }
   end
 
+  defp build_text_content_query(query, nil), do: query
   defp build_text_content_query(query, terms) do
     text_boost = Application.get_env(:ello_search, :text_content_boost_factor)
-    update_in(query[:query][:bool][:must], &([%{query_string: %{query: terms, fields: ["text_content"], boost: text_boost}} | &1]))
+    update_bool(query, :must, &([%{query_string: %{query: terms, fields: ["text_content"], boost: text_boost}} | &1]))
   end
 
+  defp build_mention_query(query, nil), do: query
   defp build_mention_query(query, terms) do
     mention_boost = Application.get_env(:ello_search, :mention_boost_factor)
-    update_in(query[:query][:bool][:should], &([%{match: %{mentions: %{query: terms, boost: mention_boost}}} | &1]))
+    update_bool(query, :should, &([%{match: %{mentions: %{query: terms, boost: mention_boost}}} | &1]))
   end
 
+  defp build_hashtag_query(query, nil), do: query
   defp build_hashtag_query(query, terms) do
     hashtag_boost = Application.get_env(:ello_search, :hashtag_boost_factor)
-    update_in(query[:query][:bool][:should], &([%{match: %{hashtags: %{query: terms, boost: hashtag_boost}}} | &1]))
+    update_bool(query, :should, &([%{match: %{hashtags: %{query: terms, boost: hashtag_boost}}} | &1]))
   end
 
   defp filter_nsfw(query, true), do: query
   defp filter_nsfw(query, false) do
-    update_in(query[:query][:bool][:must_not], &([%{term: %{is_adult_content: true}} | &1]))
+    update_bool(query, :must_not, &([%{term: %{is_adult_content: true}} | &1]))
   end
 
   defp filter_nudity(query, true), do: query
   defp filter_nudity(query, false) do
-    update_in(query[:query][:bool][:must_not], &([%{term: %{has_nudity: true}} | &1]))
+    update_bool(query, :must_not, &([%{term: %{has_nudity: true}} | &1]))
   end
 
   defp filter_blocked(query, nil), do: query
   defp filter_blocked(query, user) do
-    update_in(query[:query][:bool][:must_not], &([%{terms: %{author_id: user.all_blocked_ids}} | &1]))
+    update_bool(query, :must_not, &([%{terms: %{author_id: user.all_blocked_ids}} | &1]))
   end
 
   defp author_query do

  alias Ello.Search.{Client, PostIndex, TrendingPost, Page}
  use Timex

  def post_search(%{terms: terms} = opts) do
    opts
    |> build_client_filter_queries
    |> build_text_content_query(terms)
    |> build_mention_query(terms)
    |> build_hashtag_query(terms)
    |> build_pagination_query(opts[:page], opts[:per_page])
    |> search_post_index(opts)
  end


      results = Client.search(PostIndex.index_name(), [PostIndex.post_doc_type], query).body
    end

    posts = results
            |> get_in(["hits", "hits"])
            |> Enum.map(&(String.to_integer(&1["_id"])))
            |> Content.posts_by_ids(opts)

