anchor.diff:      ",\"sort\" : " ++UseSort++
       ",\"query\" : {\"filtered\" : "++NewJson++
       ",\"filter\" : {\"bool\" : {\"must_not\" : {\"term\" : {\"private\" : \"true\"}}}}}}}".
  +
  +filter_json_users(Json, From, Size, Sort) ->
  +    case lib_json:get_field(Json, "sort") of
  +        undefined ->
  +            UseSort = "\"" ++ Sort ++ "\"",
  +            SortJson = Json;
  +        SortValue when is_binary(SortValue) ->
  +            UseSort = "\"" ++ binary_to_list(SortValue) ++ "\"",
  +            SortJson = lib_json:rm_field(Json, "sort");
  +        SortValue ->
  +            UseSort = SortValue,
  +            SortJson = lib_json:rm_field(Json, "sort")
  +    end,
  +
  +    NewJson = string:sub_string(SortJson,1,string:len(SortJson)-1),
  +    JSON = "{\"from\" : "++From++
  +    ",\"size\" : "++Size++
  +    ",\"sort\" : " ++UseSort++
  +    ",\"_source\": { \"exclude\": [ \"access_token\", \"refresh_token\", \"password\", \"email\", \"private\" ]}"++
  +    ",\"query\" : {\"filtered\" : "++NewJson++
  +    ",\"filter\" : {\"bool\" : {\"must_not\" : {\"term\" : {\"private\" : \"true\"}}}}}}}",
  +    lib_json:rm_field(JSON, "sort").
  
positive.code: %% @end
  -spec get_search(ReqData::tuple(), State::string()) -> {string(), tuple(), string()}.
  get_search(ReqData, State) ->
      case openidc:auth_request(ReqData) of
          {error, Status, Msg} -> {{halt, Status}, wrq:set_resp_body(Msg, ReqData), State};
          {ok, _} ->
              case api_help:is_search(ReqData) of
                  false ->
                      case wrq:get_qs_value("size",ReqData) of
                              undefined ->
                                  NrValues = 25;
                              Values ->
                                  {NrValues, _} = string:to_integer(Values)
                      end,
                      case wrq:get_qs_value("stream_id",ReqData) of
                              undefined ->
                                  ErrorString = api_help:generate_error(<<"Invalid stream_id">>, 405),
                                  {{halt, 405}, wrq:set_resp_body(ErrorString, ReqData), State};
                              StreamIds ->
                                  IdList = string:tokens(StreamIds, ","),
                                  {get_history(IdList, NrValues, "{\"history\":[]}"), ReqData, State}
                      end;
                  true ->
                      {{halt, 501}, wrq:set_resp_body("Please use POST search instead.", ReqData), State}
              end
      end.
  
  %% @doc
  
negative.code: %% @end
  -spec process_post(ReqData::tuple(), State::string()) -> {true, tuple(), string()}.
  process_post(ReqData, State) ->
  		process_search_post(ReqData,State).
  
  %% @doc
  %% Function: process_search_post/2
  %% Purpose: Used to handle search requests that come from POST requests
  %% Returns: {Success, ReqData, State}, where Success is true if the search request is
  %% successful and false otherwise.
  %% @end
  -spec process_search_post(ReqData::term(),State::term()) -> {boolean(), term(), term()}.
  process_search_post(ReqData, State) ->
      erlang:display("search with json request"),
      case wrq:get_qs_value("size",ReqData) of
          undefined ->
              Size = "10";
          SizeParam ->
              Size = SizeParam
      end,
  	case wrq:get_qs_value("sort",ReqData) of
          undefined ->
              Sort = "user_ranking.average";
          SortParam ->
              Sort = SortParam
      end,
      case wrq:get_qs_value("from",ReqData) of
          undefined ->
              From = "0";
          FromParam ->
              From = FromParam
      end,
      case wrq:get_qs_value("location",ReqData) of
          undefined ->
              LocationParam = false;
          "true" ->
              LocationParam = true;
          _ ->
              LocationParam = false
      end,
      {Json,_,_} = api_help:json_handler(ReqData,State),
      FilteredJson = filter_json(Json, From, Size, Sort, LocationParam),
      case erlastic_search:search_json(#erls_params{},?INDEX, "stream", FilteredJson) of % Maybe wanna take more
              {error, Reason1} ->
                  StreamSearch = {error, Reason1};
              {ok,List1} ->
  			case lib_json:get_field(FilteredJson, "query.filtered.query.query_string.query") of
  				undefined ->
  					erlang:display("No query string text, cannot add a suggestion.");
  				QueryString ->
                      add_query_suggestion(QueryString)
  			end,
  			StreamSearch = lib_json:encode(List1) % May need to convert
      end,
      FilteredJson2 = filter_json(Json, From, Size, Sort, false),
      case erlastic_search:search_json(#erls_params{},?INDEX, "virtual_stream", lib_json:rm_field(FilteredJson2, "sort")) of % Maybe wanna take more
              {error, Reason2} ->
                  VStreamSearch = {error, Reason2};
              {ok,List2} ->
                  VStreamSearch = lib_json:encode(List2) % May need to convert
      end,
  
      U_Filter = filter_json_users(Json, From, Size, Sort),
      case erlastic_search:search_json(#erls_params{},?INDEX, "user", U_Filter) of % Maybe wanna take more
              {error, Reason3} ->
                      UserSearch = {error, Reason3};
              {ok,List3} ->
      			UserSearch = lib_json:encode(List3) % May need to convert
       end,
  	% check search-results for error
      case {StreamSearch, VStreamSearch, UserSearch} of
          {{error, {Body, Code}},_,_} ->
              ErrorString = api_help:generate_error(Body, Code),
              {{halt, Code}, wrq:set_resp_body(ErrorString, ReqData), State};
          {_,{error, {Body2, Code2}},_} ->
              ErrorString = api_help:generate_error(Body2, Code2),
              {{halt, Code2}, wrq:set_resp_body(ErrorString, ReqData), State};
          {_,_,{error, {Body3, Code3}}} ->
              ErrorString = api_help:generate_error(Body3, Code3),
              {{halt, Code3}, wrq:set_resp_body(ErrorString, ReqData), State};
          _ ->
              SearchResults = "{\"streams\":"++ StreamSearch ++",\"vstreams\":"++ VStreamSearch ++",\"users\":"++ UserSearch ++"}",
              {true,wrq:set_resp_body(SearchResults,ReqData),State}
      end.
  
  %% GROUPS ARE NOT IMPLEMENTED
  %%         case erlastic_search:search_json(#erls_params{},?INDEX, "group", FilteredJson) of % Maybe wanna take more
  %%                 {error,Reason} -> {{halt,Reason}, ReqData, State};
  %%                 {ok,List} -> {true,wrq:set_resp_body(json_encode(List),ReqData),State} % May need to convert
  %%         end.
  
  
  
  
  %% @doc
  