@@ -9,15 +9,15 @@ defmodule CodeCorps.ElasticSearchHelper do
99
1010 def create_index ( url , index , type ) do
1111 Index . settings ( url , index , settings_map ( ) )
12- Index . settings ( url , "#{ index } /_mapping/#{ type } " , field_filter ( ) )
12+ Index . settings ( url , "#{ index } /_mapping/#{ type } " , field_filter ( type ) )
1313 end
1414
1515 def add_documents ( url , index , type , documents ) when is_list ( documents ) do
1616 add_documents ( url , index , type , documents , [ ] )
1717 end
1818
1919 def add_documents ( url , index , type , documents , query ) when is_list ( documents ) do
20- Enum . each ( documents , fn ( x ) -> add_document ( url , index , type , to_map ( type , x ) , query ) end )
20+ Enum . each ( documents , fn ( x ) -> add_document ( url , index , type , % { " #{ type } " => x } , query ) end )
2121 end
2222
2323 def add_document ( url , index , type , data ) do
@@ -31,10 +31,9 @@ defmodule CodeCorps.ElasticSearchHelper do
3131 def search ( url , index , type , search_query ) do
3232 data = % {
3333 query: % {
34- match: to_map ( type , search_query )
34+ match: % { " #{ type } ": search_query }
3535 }
3636 }
37-
3837 Search . search ( url , index , [ ] , data ) |> process_response ( type )
3938 end
4039
@@ -44,8 +43,6 @@ defmodule CodeCorps.ElasticSearchHelper do
4443
4544 def process_response ( _ ) , do: [ ]
4645
47- def to_map ( foo , bar ) , do: % { String . to_atom ( foo ) => bar }
48-
4946 defp settings_map do
5047 % {
5148 settings: % {
@@ -73,13 +70,13 @@ defmodule CodeCorps.ElasticSearchHelper do
7370 }
7471 end
7572
76- defp field_filter do
73+ def field_filter ( type ) do
7774 % {
78- title: % {
79- properties: % {
80- title: % {
81- "type": "string" ,
82- "analyzer": "autocomplete"
75+ " #{ type } " => % {
76+ " properties" => % {
77+ " #{ type } " => % {
78+ "type" => "string" ,
79+ "analyzer" => "autocomplete"
8380 }
8481 }
8582 }
0 commit comments