anchor.diff:  		   {"query.filtered.filter.range.timestamp", "{}"},
   		   {"query.filtered.filter.range.timestamp.gte", TimestampFrom}
   	]),
  -	
  +
   	Interval = binary_to_list(lists:nth(2, Function)),
   	Facet = [{"facets", "{}"},
   			{"facets.statistics", "{}"},
  
positive.code: %% @end
  -spec put_stream(ReqData::term(),State::term()) -> {boolean(), term(), term()}.
  put_stream(ReqData, State) ->
  	VStreamId = proplists:get_value('id', wrq:path_info(ReqData)),
  	{VStream,_,_} = api_help:json_handler(ReqData,State),
  	Update = lib_json:set_attr(doc,VStream),
  	case api_help:do_only_fields_exist(VStream,?ACCEPTED_FIELDS_VSTREAMS_UPDATE) of
  		true-> 
  			case api_help:update_doc(?INDEX, "virtual_stream", VStreamId, Update) of 
  				{error, {Code, Body}} -> 
  					ErrorString = api_help:generate_error(Body, Code),
  					{{halt, Code}, wrq:set_resp_body(ErrorString, ReqData), State};
  				{ok,List} -> 
  					{true,wrq:set_resp_body(lib_json:encode(List),ReqData),State}
  			end;
  		false ->
  			{{halt,403}, wrq:set_resp_body("Unsupported field(s)", ReqData), State}
  	end.
  
  
  %% @doc
  %% Function: delete_resource/2
  %% Purpose: Used to handle DELETE requests for deleting the virtual stream and its 
  %% vsdatapoints in elastic search
  %% Returns: {Success, ReqData, State}, where Success is true if delete is successful
  %% and false otherwise.
  
negative.code: %% @end
  -spec process_post(ReqData::tuple(), State::string()) -> {true, tuple(), string()}.
  process_post(ReqData, State) ->
  	case openidc:authenticate_request(ReqData) of
          {error, Msg} -> {{halt, 403}, wrq:set_resp_body(Msg, ReqData), State};
          {ok, Token} ->
  			case api_help:is_search(ReqData) of
  				false ->
  					{VirtualStreamJson,_,_} = api_help:json_handler(ReqData, State),
  					{{Year,Month,Day},{Hour,Minute,Second}} = calendar:local_time(),
  					Date = api_help:generate_date([Year,Month,Day]),
  					DateAdded = lib_json:add_values(VirtualStreamJson,[{creation_date, list_to_binary(Date)}]),
  					StreamsInvolved = lib_json:get_field(VirtualStreamJson, "streams_involved"),
  					TimestampFrom = lib_json:get_field(VirtualStreamJson, "timestampfrom"),
  					Function = lib_json:get_field(VirtualStreamJson, "function"),
  					AllowedFunctions = ["min", "max", "mean", "total", "diff"],
  					case api_help:do_only_fields_exist(VirtualStreamJson,?ACCEPTED_FIELDS_VSTREAMS_CREATE) of
  						true->
  							case lists:member(binary_to_list(lists:nth(1, Function)), AllowedFunctions) of
  								true ->
  									Func = binary_to_list(lists:nth(1, Function)),
  									if
  										Func == "diff" andalso length(StreamsInvolved) =/= 1 ->
  											{{halt, 404}, wrq:set_resp_body("Wrong number of streams involved for diff", ReqData), State};
  										true ->
  											{{Year,Month,Day},{Hour,Minute,Second}} = calendar:local_time(),
  											TimeStamp = binary:list_to_bin(api_help:generate_timestamp([Year,Month,Day,Hour,Minute,Second],0)),
  											Initialized = lib_json:add_field(DateAdded,"last_updated",TimeStamp),
  											case erlastic_search:index_doc(?INDEX, "virtual_stream", Initialized) of
  												{error, Reason} ->
  													{{error,Reason}, wrq:set_resp_body("{\"error\":\""++ atom_to_list(Reason) ++ "\"}", ReqData), State};
  												{ok,List} ->
  													VirtualStreamId = lib_json:get_field(List, "_id"),
  													if
  														Func == "diff" ->
  															ok;
  														true ->
  															reduce(VirtualStreamId, StreamsInvolved, TimestampFrom, Function, ReqData, State)
  													end,
  													StreamList = [{stream, binary_to_list(X)} || X <- StreamsInvolved],
  													virtual_stream_process_supervisor:add_child(binary_to_list(VirtualStreamId), StreamList, Function),
  													{true, wrq:set_resp_body(lib_json:encode(List), ReqData), State}
  											end
  									end;
  								false ->
  									{{halt, 404}, wrq:set_resp_body("404 Function missing or not supported", ReqData), State}
  							end;
  						false->
  							{{halt,403}, wrq:set_resp_body("Unsupported field(s), virtual stream not created", ReqData), State}
  					end;
  				true ->
  					process_search(ReqData, State, post)
  			end
  	end.
  
  
  