anchor.diff:  		false ->
   			erlang:display("update request"),
   			{Stream,_,_} = json_handler(ReqData,State),
  -			case erlastic_search:index_doc("streams","stream",Stream) of
  +			case erlastic_search:index_doc(?INDEX,"stream",Stream) of %should update instead
   				{error,Reason} -> {{error,Reason}, ReqData, State};
  -				{ok,_List} -> {true,ReqData,State}
  +				{ok,List} -> {json_encode(List),ReqData,State}
   			end;
   		true ->
   			erlang:display("search request"),
   			URIQuery = wrq:req_qs(ReqData),
   			case proplists:get_value('user', wrq:path_info(ReqData)) of
   				undefined ->
  -					UserQuery = [];
  +					UserQuery = [],
  +					UserDef = false;
   				UserId ->
  -					UserQuery = ["q=owner_id:" ++ lists:nth(1,UserId)]
  +					UserQuery = "owner_id:" ++ UserId,
  +					UserDef = true
   			end,
   			case proplists:get_value('res', wrq:path_info(ReqData)) of
   				undefined ->
  -					ResQuery = [];
  +					ResQuery = [],
  +					ResDef = false;
   				ResId ->
  -					ResQuery = ["q=resource_id:" ++ lists:nth(1,ResId)]
  -			end,
  -			SearchQuery = lists:append(URIQuery,lists:append(UserQuery,ResQuery)),
  -			case erlastic_search:search_limit("streams", "stream", SearchQuery,100) of % Maybe wanna take more
  +					ResQuery = "resource_id:" ++ ResId,
  +					ResDef = true
  +			end,
  +			case ResDef and UserDef of
  +				true -> Query = ResQuery;
  +				false -> case ResDef or UserDef of
  +							 true -> Query = UserQuery ++ ResQuery;
  +							 false -> Query = ""
  +						 end
  +			end,
  +			FullQuery = lists:append(transform(URIQuery,ResDef or UserDef),Query),
  +			erlang:display(FullQuery),
  +			case erlastic_search:search_limit(?INDEX, "stream", FullQuery,10) of % Maybe wanna take more
   				{error,Reason} -> {{error,Reason}, ReqData, State};
   				{ok,List} -> {List,ReqData,State} % May need to convert
   			end
  
positive.code: %% @end
  
  allowed_methods(ReqData, State) ->
          erlastic_search_app:start(),
  	case parse_path(wrq:path(ReqData)) of
  		[{"streams"}] ->
  			{['POST','GET'], ReqData, State};
  		[{"streams", _StreamID}] ->
  			{['GET', 'PUT', 'DELETE'], ReqData, State};
  		[{"users", _UserID, "resources", _ResourceID, "streams", "_search"}] ->
  		  	{['POST'], ReqData, State};
  		[{"users", _UserID, "resources", _ResourceID, "streams", _StreamID}] ->
  			{['GET', 'PUT', 'DELETE'], ReqData, State};
  		[{"users", _UserID, "resources", _ResourceID, "streams"}] ->
  			{['GET','POST'], ReqData, State};
  		[{"users", _UserID, "streams", "_search"}] ->
  			{['POST'], ReqData, State};
  		[{"users", _UserID, "streams", _StreamID}] ->
  			{['GET', 'PUT', 'DELETE'], ReqData, State};
  		[{"users", _UserID, "streams"}] ->
  			{['GET','POST'], ReqData, State};
  		[{"streams", "_search"}] ->
  			{['POST'], ReqData, State};
  		[error] ->
  		        {['POST','GET'], ReqData, State}
  end.
  
  
  
negative.code: 	case proplists:get_value('stream', wrq:path_info(ReqData)) of
  		undefined ->
  		% List streams based on URI
  		    erlang:display("Value undefined"),
  			case proplists:get_value('user', wrq:path_info(ReqData)) of
  				undefined ->
  					UserQuery = [],
  					UserDef = false;
  				UserId ->
  					UserQuery = "owner_id:" ++ UserId,
  					UserDef = true
  			end,
  			case proplists:get_value('res', wrq:path_info(ReqData)) of
  				undefined ->
  					ResQuery = [],
  					ResDef = false;
  				ResId ->
  					ResQuery = "resource_id:" ++ ResId,
  					ResDef = true
  			end,
  			case ResDef and UserDef of
  				true -> Query = ResQuery;
  				false -> case ResDef or UserDef of
  							 true -> Query = UserQuery ++ ResQuery;
  							 false -> Query = "*"
  						 end
  			end,
  			case erlastic_search:search_limit(?INDEX, "stream", Query, 10) of % Maybe wanna take more
  				{error,Reason} -> {{error, Reason}, ReqData, State};
  				{ok,List} -> {json_encode(List), ReqData, State} % Maybe need to convert
  			end;
  		StreamId ->
  		        erlang:display("Value defined"),
  		% Get specific stream
  			case erlastic_search:get_doc(?INDEX, "stream", StreamId) of 
  				{error, Msg} -> 
  						erlang:display("got error"),
  						{Msg, ReqData, State};
  				{ok,List} -> 
  						 erlang:display("got value"),
  					     {json_encode(List), ReqData, State}
  			end
  	end.
  
  