Skip to content

Commit 86ea94c

Browse files
committed
MAGETWO-94172: Elasticsearch 5.0+ exception is shown if customer searches product before reindexing
Check index before performing elastic search and return raw response
1 parent b55989d commit 86ea94c

File tree

1 file changed

+18
-4
lines changed
  • app/code/Magento/Elasticsearch/Elasticsearch5/SearchAdapter

1 file changed

+18
-4
lines changed

app/code/Magento/Elasticsearch/Elasticsearch5/SearchAdapter/Adapter.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,27 @@ public function query(RequestInterface $request)
7676
{
7777
$client = $this->connectionManager->getConnection();
7878
$aggregationBuilder = $this->aggregationBuilder;
79-
8079
$query = $this->mapper->buildQuery($request);
8180
$aggregationBuilder->setQuery($this->queryContainerFactory->create(['query' => $query]));
82-
$rawResponse = $client->query($query);
83-
81+
if ($client->indexExists($query['index'])) {
82+
$rawResponse = $client->query($query);
83+
} else {
84+
$rawResponse = [
85+
"hits" =>
86+
[
87+
"hits" => []
88+
],
89+
"aggregations" =>
90+
[
91+
"price_bucket" => [],
92+
"category_bucket" =>
93+
[
94+
"buckets" => []
95+
]
96+
]
97+
];
98+
}
8499
$rawDocuments = isset($rawResponse['hits']['hits']) ? $rawResponse['hits']['hits'] : [];
85-
86100
$queryResponse = $this->responseFactory->create(
87101
[
88102
'documents' => $rawDocuments,

0 commit comments

Comments
 (0)