@@ -8,8 +8,8 @@ defmodule CodeCorps.ElasticSearchHelper do
88 end
99
1010 def create_index ( url , index , type ) do
11- Index . settings ( url , index , settings_map )
12- Index . settings ( url , "#{ index } /_mapping/#{ type } " , field_filter )
11+ Index . settings ( url , index , settings_map ( ) )
12+ Index . settings ( url , "#{ index } /_mapping/#{ type } " , field_filter ( ) )
1313 end
1414
1515 def add_documents ( url , index , type , documents ) when is_list ( documents ) do
@@ -35,15 +35,15 @@ defmodule CodeCorps.ElasticSearchHelper do
3535 }
3636 }
3737
38- response = Search . search url , index , [ ] , data
39-
40- #response.status_code == 200 do
41- #count = response.body["hits"]["total"]
38+ Search . search ( url , index , [ ] , data ) |> process_response ( type )
39+ end
4240
43- hits = response . body [ "hits" ] [ "hits" ] || [ ]
44- Enum . map ( hits , fn ( x ) -> x [ "_source" ] [ "title" ] end )
41+ def process_response ( % HTTPoison.Response { status_code: 200 } = response , type ) do
42+ response . body [ "hits" ] [ "hits" ] |> Enum . map ( fn ( x ) -> x [ "_source" ] [ type ] end )
4543 end
4644
45+ def process_response ( _ ) , do: [ ]
46+
4747 def to_map ( foo , bar ) , do: % { String . to_atom ( foo ) => bar }
4848
4949 defp settings_map do
0 commit comments