anchor.diff:  		   {"query.filtered", "{}"},
   		   {"query.filtered.query", "{}"},
   		   {"query.filtered.query.terms", "{}"},
  -		   {"query.filtered.query.terms.streamid", Streams},
  +		   {"query.filtered.query.terms.stream_id", Streams},
   		   {"query.filtered.filter", "{}"},
   		   {"query.filtered.filter.range", "{}"},
   		   {"query.filtered.filter.range.timestamp", "{}"},
  
positive.code: 	]),
  	case string:str(Function, [<<"aggregate">>]) of %is aggregate the proper name? maybe groupby?
              0 -> %	   	["min" "max" "mean" "???average???" "sum_of_squares" "variance" "std_deviation" ->
  		  				 %the following are without aggregation, just statistics   .
  						%min, max etc are not added in the query yet, I will investigate if it is even possible
  					Facet =  [{"facets", "{}"},
  						  	 {"facets.statistics", "{}"},
  						  	 {"facets.statistics.statistical", "{}"},
  						  	 {"facets.statistics.statistical.script", '(Long) _source.value'}]; %I have to get the value here in another way
  			_ -> %		["aggregate", "min" "max" "total(==sum)" ] ->		can also support custom calculations like *,+,-,/, ^(prob)
  					% as above
  					Facet = [{"facets", "{}"},
  							{"facets.tag_price_stats", "{}"},
  							{"facets.tag_price_stats.terms_stats", "{}"},
  							{"facets.tag_price_stats.terms_stats.key_field", 'timestamp'},
  							{"facets.tag_price_stats.terms_stats.value_script", '(Long) _source.value'},
  							{"facets.tag_price_stats.terms_stats.size", 100}] %necessary????
  	end,
  	lib_json:add_values(Query, Facet)
  .
  
  
  %% @doc
  %% Function: generate_date/2
  %% Purpose: Used to create a date valid in ES
  %%          from the input which should be the list
  %%          [Year,Mounth,Day]
  %% Returns: The generated timestamp
  %%
  %% @end
  -spec generate_date(DateList::list()) -> string().
  
  generate_date([First]) ->
  	case First < 10 of
  		true -> "0" ++ integer_to_list(First);
  		false -> "" ++ integer_to_list(First)
  	end;
  generate_date([First|Rest]) ->
  	case First < 10 of
  		true -> "0" ++ integer_to_list(First) ++ "-" ++ generate_date(Rest);
  		false -> "" ++ integer_to_list(First) ++ "-" ++ generate_date(Rest)
  	end.
  
negative.code: 	% what do we store if whe do not aggregate and thus the statistics are only a single value?
  			case string:str(Function, [<<"aggregate">>]) of %is aggregate the proper name? maybe groupby?
              	0 ->
  					{{Year,Month,Day},{Hour,Minute,Second}} = calendar:local_time(),
  					TimeStamp = api_help:generate_timestamp([Year,Month,Day,Hour,Minute,Second],0), % to be reconsidered
  					Datapoint = lib_json:get_field(JsonStruct, "facets.statistics"),
  					FinalDatapoint = lib_json:set_attrs([
  														   {"timestamp", list_to_atom(TimeStamp)}, %does timestamp have a meaning here? maybe do a reverse search for the time???
  														   {"stream_id", list_to_atom(binary_to_list(VirtualStreamId))},
  														   {"value",  lib_json:get_field(Datapoint, binary_to_list(lists:nth(1, Function)))}
  														  ]),
  erlang:display(FinalDatapoint),
  					case erlastic_search:index_doc(?INDEX, "datapoint", FinalDatapoint) of 
  						{error, Reason2} -> erlang:display("Error");
  						{ok,JsonStruct2} ->	erlang:display("Correct")						
  					end;
  				_->
  					DatapointsList = lib_json:get_field(JsonStruct, "facets.statistics.entries"),
  					NewDatapoints = lists:map(fun(Json) -> 
  													  FinalDatapoint = lib_json:set_attrs([
  																						   {"timestamp", list_to_atom(msToDate(lib_json:get_field(Json, "key")))},
  																						   {"stream_id", VirtualStreamId},
  																						   {"value",  lib_json:get_field(Json, binary_to_list(lists:nth(2, Function)))}
  																						  ]),
  													erlang:display(FinalDatapoint),
  													  erlastic_search:index_doc(?INDEX, "datapoint", lib_json:to_string(FinalDatapoint)) %to add error check here
  											  end, DatapointsList)
  			
  			%%will post all datapoints one by one, improve with bulk posting should be like the following
  