diff --git a/lib/shop_invader/services/elastic_service.rb b/lib/shop_invader/services/elastic_service.rb index 20c85e9..af663c4 100644 --- a/lib/shop_invader/services/elastic_service.rb +++ b/lib/shop_invader/services/elastic_service.rb @@ -50,7 +50,9 @@ 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 @@ -58,7 +60,9 @@ def find_all_products_and_categories 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