Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip item that do not have url_key #84

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/shop_invader/services/elastic_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,19 @@ def find_all_products_and_categories
# first search which also returns _scroll_id
result['hits']['hits'].each do |hit|
record = records[hit['_id']] ||= {}
record[locale] = { name: hit['_source']['name'], url: find_route(config['name']).gsub('*', hit['_source']['url_key']) }
if hit['_source']['url_key']
record[locale] = { name: hit['_source']['name'], url: find_route(config['name']).gsub('*', hit['_source']['url_key']) }
end
end

# Uses the `scroll` API until empty results are returned
# https://www.elastic.co/guide/en/elasticsearch/reference/6.6/search-request-scroll.html
while result = @client.scroll(body: { scroll_id: result['_scroll_id'] }, scroll: '5m') and not result['hits']['hits'].empty? do
result['hits']['hits'].each do |hit|
record = records[hit['_id']] ||= {}
record[locale] = { name: hit['_source']['name'], url: find_route(config['name']).gsub('*', hit['_source']['url_key']) }
if hit['_source']['url_key']
record[locale] = { name: hit['_source']['name'], url: find_route(config['name']).gsub('*', hit['_source']['url_key']) }
end
end
end
end
Expand Down
Loading