Skip to content

Commit 135c855

Browse files
committed
Skip item that do not have urlkey
1 parent 5ed2075 commit 135c855

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/shop_invader/services/elastic_service.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,19 @@ def find_all_products_and_categories
5050
# first search which also returns _scroll_id
5151
result['hits']['hits'].each do |hit|
5252
record = records[hit['_id']] ||= {}
53-
record[locale] = { name: hit['_source']['name'], url: find_route(config['name']).gsub('*', hit['_source']['url_key']) }
53+
if hit['_source']['url_key']
54+
record[locale] = { name: hit['_source']['name'], url: find_route(config['name']).gsub('*', hit['_source']['url_key']) }
55+
end
5456
end
5557

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

0 commit comments

Comments
 (0)