Skip to content

Commit

Permalink
knife fix when the rows in wild search exceeds 10k.
Browse files Browse the repository at this point in the history
Signed-off-by: talktovikas <[email protected]>
  • Loading branch information
talktovikas committed Dec 12, 2024
1 parent 599127a commit 6ca1f97
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
{timeout, <%= @solr_timeout %>},
{init_count, <%= @solr_http_init_count %>},
{max_count, <%= @solr_http_max_count %>},
{track_total_hits, <%= @solr_track_total_hits %>},
{cull_interval, <%= @solr_http_cull_interval %>},
{max_age, <%= @solr_http_max_age %>},
{max_connection_duration, <%= @solr_http_max_connection_duration %>},
Expand Down
1 change: 1 addition & 0 deletions src/oc_erchef/apps/chef_index/src/chef_index_query.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ from_params(Provider, ObjType, QueryString, Start, Rows) ->
search_provider = Provider,
start = decode({nonneg_int, "start"}, Start, 0),
rows = decode({nonneg_int, "rows"}, Rows, 1000),
track_total_hits = envy:get(chef_index, track_total_hits, false, boolean),
sort = "X_CHEF_id_CHEF_X asc",
index = index_type(ObjType)}.

Expand Down
33 changes: 33 additions & 0 deletions src/oc_erchef/apps/chef_index/src/chef_opensearch.erl
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,54 @@ query_body(#chef_solr_query{
query_string = Query,
filter_query = undefined,
start = Start,
track_total_hits = true,
rows = Rows}) ->
jiffy:encode({[{fields_tag(), <<"_id">>},
{<<"from">>, Start},
{<<"size">>, Rows},
{<<"track_total_hits">>,true},
{<<"query">>, {[query_string_query_ejson(Query)]}}
]});
query_body(#chef_solr_query{
query_string = Query,
filter_query = undefined,
start = Start,
track_total_hits = false,
rows = Rows}) ->
jiffy:encode({[{fields_tag(), <<"_id">>},
{<<"from">>, Start},
{<<"size">>, Rows},
{<<"query">>, {[query_string_query_ejson(Query)]}}
]});

query_body(#chef_solr_query{
query_string = Query,
filter_query = FilterQuery,
start = Start,
track_total_hits = false,
rows = Rows}) ->
chef_index_query:assert_org_id_filter(FilterQuery),
jiffy:encode({[{ fields_tag(), <<"_id">>},
{<<"from">>, Start},
{<<"size">>, Rows},
{<<"sort">>, [{[{<<"X_CHEF_id_CHEF_X">>, {[{<<"order">>, <<"asc">>}]}}]}]},
{<<"query">>, {[
{<<"bool">>,{[
{<<"must">>, {[query_string_query_ejson(Query)]}},
{<<"filter">>, {[query_string_query_ejson(FilterQuery)]}}
]}}]}
}]});
query_body(#chef_solr_query{
query_string = Query,
filter_query = FilterQuery,
start = Start,
track_total_hits = true,
rows = Rows}) ->
chef_index_query:assert_org_id_filter(FilterQuery),
jiffy:encode({[{ fields_tag(), <<"_id">>},
{<<"from">>, Start},
{<<"size">>, Rows},
{<<"track_total_hits">>,true},
{<<"sort">>, [{[{<<"X_CHEF_id_CHEF_X">>, {[{<<"order">>, <<"asc">>}]}}]}]},
{<<"query">>, {[
{<<"bool">>,{[
Expand Down
2 changes: 2 additions & 0 deletions src/oc_erchef/apps/chef_index/test/chef_index_query_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ query_from_params_test_() ->
sort = "X_CHEF_id_CHEF_X asc",
start = 2,
rows = 5,
track_total_hits=false,
index = node},
?assertEqual(Expect, Query)
end},
Expand All @@ -57,6 +58,7 @@ query_from_params_test_() ->
sort = "X_CHEF_id_CHEF_X asc",
start = 0,
rows = 1000,
track_total_hits=false,
index = role},
?assertEqual(Expect, Query)
end},
Expand Down
1 change: 1 addition & 0 deletions src/oc_erchef/habitat/config/sys.config
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
{search_batch_max_wait, 10},
{reindex_sleep_min_ms, 500},
{reindex_sleep_max_ms, 2000},
{track_total_hits,false},
{reindex_item_retries, 3},
{solr_elasticsearch_major_version, 5},
{solr_service, [
Expand Down
1 change: 1 addition & 0 deletions src/oc_erchef/include/chef_solr.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
search_provider = solr :: 'solr' | 'elasticsearch' | 'opensearch',
start :: integer() | undefined,
rows :: integer() | undefined,
track_total_hits :: boolean() |undefined,
sort :: string() | undefined,
index :: 'node'
| 'role'
Expand Down

0 comments on commit 6ca1f97

Please sign in to comment.