From eac23f4d66b86f3d59e8c7a6836db04d3dfff0da Mon Sep 17 00:00:00 2001 From: Prasad Date: Fri, 19 Aug 2016 01:56:21 +0530 Subject: [PATCH 1/3] Added scroll support Before calling search_scroll/1 function, the search_scroll/4 function should be called with index, type name and the search query. Based on the search response, "scroll_id" can be passed to search_scroll/1 to get next batch results. --- src/erlastic_search.erl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/erlastic_search.erl b/src/erlastic_search.erl index 72d16f4..8f814a3 100644 --- a/src/erlastic_search.erl +++ b/src/erlastic_search.erl @@ -32,6 +32,8 @@ ,search/3 ,search/5 ,search_limit/4 + ,search_scroll/4 + ,search_scroll/1 ,get_doc/3 ,get_doc/4 ,flush_index/1 @@ -230,6 +232,23 @@ search(Index, Type, Query) -> search_limit(Index, Type, Query, Limit) when is_integer(Limit) -> search(#erls_params{}, Index, Type, Query, [{<<"size">>, integer_to_list(Limit)}]). +%%-------------------------------------------------------------------- +%% @doc +%% search_scroll/4 -- Takes the index, type name and search query +%% sends it to the Elasticsearch server specified in Params. +%% Returns search results along with scroll id which can be passed +%% to search_scroll/1 to get next set of search results +%% @end +%%-------------------------------------------------------------------- +-spec search_scroll(binary() | list(), binary(), erlastic_json() | binary(), list()) -> {ok, erlastic_success_result()} | {error, any()}. +search_scroll(Index, Type, Query, Timeout) -> + search(#erls_params{}, Index, Type, Query, [{<<"scroll">>, list_to_binary(Timeout)}]). + +-spec search_scroll(binary()) -> {ok, erlastic_success_result()} | {error, any()}. +search_scrolling(Query) -> + Params = #erls_params{}, + erls_resource:post(Params, filename:join([<<"_search">>, <<"scroll">>]), [], [], erls_json:encode(Query), Params#erls_params.http_client_options). + -spec search(#erls_params{}, list() | binary(), list() | binary(), erlastic_json() | binary(), list()) -> {ok, erlastic_success_result()} | {error, any()}. search(Params, Index, Type, Query, Opts) when is_binary(Query) -> erls_resource:get(Params, filename:join([commas(Index), Type, <<"_search">>]), [], [{<<"q">>, Query}]++Opts, Params#erls_params.http_client_options); From 071e4207d045764d8015ac155c4414b24ba79c9c Mon Sep 17 00:00:00 2001 From: Prasad Date: Fri, 19 Aug 2016 12:05:49 +0530 Subject: [PATCH 2/3] Corrected the function name --- src/erlastic_search.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/erlastic_search.erl b/src/erlastic_search.erl index 8f814a3..98557cf 100644 --- a/src/erlastic_search.erl +++ b/src/erlastic_search.erl @@ -245,7 +245,7 @@ search_scroll(Index, Type, Query, Timeout) -> search(#erls_params{}, Index, Type, Query, [{<<"scroll">>, list_to_binary(Timeout)}]). -spec search_scroll(binary()) -> {ok, erlastic_success_result()} | {error, any()}. -search_scrolling(Query) -> +search_scroll(Query) -> Params = #erls_params{}, erls_resource:post(Params, filename:join([<<"_search">>, <<"scroll">>]), [], [], erls_json:encode(Query), Params#erls_params.http_client_options). From 90431cf34dff9120ab477e5a6f5da019e0161394 Mon Sep 17 00:00:00 2001 From: Prasad Date: Fri, 19 Aug 2016 12:22:18 +0530 Subject: [PATCH 3/3] Corrected spec --- src/erlastic_search.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/erlastic_search.erl b/src/erlastic_search.erl index 98557cf..c294e4c 100644 --- a/src/erlastic_search.erl +++ b/src/erlastic_search.erl @@ -244,7 +244,7 @@ search_limit(Index, Type, Query, Limit) when is_integer(Limit) -> search_scroll(Index, Type, Query, Timeout) -> search(#erls_params{}, Index, Type, Query, [{<<"scroll">>, list_to_binary(Timeout)}]). --spec search_scroll(binary()) -> {ok, erlastic_success_result()} | {error, any()}. +-spec search_scroll(erlastic_json() | binary()) -> {ok, erlastic_success_result()} | {error, any()}. search_scroll(Query) -> Params = #erls_params{}, erls_resource:post(Params, filename:join([<<"_search">>, <<"scroll">>]), [], [], erls_json:encode(Query), Params#erls_params.http_client_options).