anchor.diff:  %% A code 406 is returned to the client if we cannot return the media-type that the user has requested.
   %% Returns: {[{Mediatype, Handler}], ReqData, State}
   %% @end
  +-spec content_types_provided(ReqData::term(),State::term()) -> {list(), term(), term()}.
  +
   content_types_provided(ReqData, State) ->
   	{[{"application/json", get_stream}], ReqData, State}.
   
  
positive.code: 				end
  	end.
  
  
  
  is_search(ReqData) ->
  	URIList = string:tokens(wrq:path(ReqData), "/"),
  	IsSearch = (string:sub_string(lists:nth(length(URIList),URIList),1,7) == "_search").
  
  json_handler(ReqData, State) ->
  	[{Value,_ }] = mochiweb_util:parse_qs(wrq:req_body(ReqData)), 
  	%%{struct, JsonData} = mochijson2:decode(Value),
  	{Value, ReqData, State}.
  
  is_query_empty({struct,[{_,_},{_,_},{_,{struct,[{_,_},{_,_},{_,0}]}},_]}) ->
  	true;
  is_query_empty(_) ->
  	false.
  
  create_update(Stream) ->
  	"{\n\"doc\" : " ++ Stream ++ "\n}".
  
  convert_binary_to_string([]) ->
  	[];
  convert_binary_to_string([First|Rest]) ->
  	case is_binary(First) of
  		true -> binary_to_list(First) ++ convert_binary_to_string(Rest);
  		false -> case is_list(First) of
  					 true -> convert_binary_to_string(First) ++ convert_binary_to_string(Rest);
  					 false -> [First] ++ convert_binary_to_string(Rest)
  				 end
  	end.
  
  add_field(Stream,FieldName,FieldValue) ->
  	string:substr(Stream,1,length(Stream)-2) ++ ",\n" ++ FieldName ++ " : " ++ FieldValue ++ "\n}".
  	
  clear_qoutes([]) ->
  	[];
  clear_qoutes(["\""|Rest]) ->
  	clear_qoutes(Rest);
  clear_qoutes([First|Rest]) ->
  	[First] ++ clear_qoutes(Rest).
  
  %% @doc
  %% Function: merge_lists/2
  
negative.code: %% A code 406 is returned to the client if we don't accept a media type that the client has sent.
  %% Returns: {[{Mediatype, Handler}], ReqData, State}
  %% @end
  -spec content_types_accepted(ReqData::term(),State::term()) -> {list(), term(), term()}.
  
  content_types_accepted(ReqData, State) ->
  	{[{"application/json", put_stream}], ReqData, State}.
  
  
  
  
  
  %% @doc
  %% Function: delete_resource/2
  %% Purpose: Used to handle DELETE requests by deleteing the stream in elastic search
  %% Returns: {Sucess, ReqData, State}, where Sucess is true if delete is sucessful
  %%			and false otherwise.
  %% @end
  -spec delete_resource(ReqData::term(),State::term()) -> {boolean(), term(), term()}.
  
  delete_resource(ReqData, State) ->
  	Id = proplists:get_value('stream', wrq:path_info(ReqData)),
  	erlang:display("delete request"),
  	erlang:display(Id),
  	case erlastic_search:delete_doc(?INDEX,"stream", Id) of
  			{error,Reason} -> {false, wrq:set_resp_body(json_encode(Reason),ReqData), State};
  			{ok,List} -> {true,wrq:set_resp_body(json_encode(List),ReqData),State}
  	end.
  
  
  %% @doc
  %% Function: process_post/2
  %% Purpose: Used to handle POST requests by creating streams, or search for streams in elastic search
  %% Returns: {Sucess, ReqData, State}, where Sucess is true if the post request is 
  %%          sucessful and false otherwise.
  %% @end
  -spec process_post(ReqData::term(),State::term()) -> {boolean(), term(), term()}.
  
  process_post(ReqData, State) ->
  	case is_search(ReqData) of 
  		false ->
  