Skip to content

Commit 59b3c08

Browse files
committed
Fix Scroll and ClearScroll syntax
1 parent 07ff0be commit 59b3c08

File tree

3 files changed

+50
-26
lines changed

3 files changed

+50
-26
lines changed

src/Elasticsearch/Client.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -985,13 +985,15 @@ public function scroll($params = array())
985985
{
986986
$scrollID = $this->extractArgument($params, 'scroll_id');
987987
$body = $this->extractArgument($params, 'body');
988+
$scroll = $this->extractArgument($params, 'scroll');
988989

989990
/** @var callback $endpointBuilder */
990991
$endpointBuilder = $this->endpoints;
991992

992993
/** @var \Elasticsearch\Endpoints\Scroll $endpoint */
993994
$endpoint = $endpointBuilder('Scroll');
994995
$endpoint->setScrollID($scrollID)
996+
->setScroll($scroll)
995997
->setBody($body);
996998
$endpoint->setParams($params);
997999

@@ -1015,11 +1017,10 @@ public function clearScroll($params = array())
10151017
/** @var callback $endpointBuilder */
10161018
$endpointBuilder = $this->endpoints;
10171019

1018-
/** @var \Elasticsearch\Endpoints\Scroll $endpoint */
1019-
$endpoint = $endpointBuilder('Scroll');
1020+
/** @var \Elasticsearch\Endpoints\ClearScroll $endpoint */
1021+
$endpoint = $endpointBuilder('ClearScroll');
10201022
$endpoint->setScrollID($scrollID)
1021-
->setBody($body)
1022-
->setClearScroll(true);
1023+
->setBody($body);
10231024
$endpoint->setParams($params);
10241025

10251026
return $this->performRequest($endpoint);

src/Elasticsearch/Endpoints/ClearScroll.php

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@
1616
class ClearScroll extends AbstractEndpoint
1717
{
1818
// A comma-separated list of scroll IDs to clear
19-
private $scroll_id;
19+
private $scrollId;
2020

2121
/**
2222
* @param $scroll_id
2323
*
2424
* @return $this
2525
*/
26-
public function setScroll_Id($scroll_id)
26+
public function setScrollId($scrollId)
2727
{
28-
if (isset($scroll_id) !== true) {
28+
if (isset($scrollId) !== true) {
2929
return $this;
3030
}
3131

32-
$this->scroll_id = $scroll_id;
32+
$this->scrollId = $scrollId;
3333

3434
return $this;
3535
}
@@ -40,19 +40,38 @@ public function setScroll_Id($scroll_id)
4040
*/
4141
public function getURI()
4242
{
43-
if (isset($this->scroll_id) !== true) {
44-
throw new Exceptions\RuntimeException(
45-
'scroll_id is required for Clearscroll'
46-
);
47-
}
48-
$scroll_id = $this->scroll_id;
49-
$uri = "/_search/scroll/$scroll_id";
43+
return "/_search/scroll/";
44+
}
5045

51-
if (isset($scroll_id) === true) {
52-
$uri = "/_search/scroll/$scroll_id";
46+
/**
47+
* @param array $body
48+
*
49+
* @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException
50+
* @return $this
51+
*/
52+
public function setBody($body)
53+
{
54+
if (isset($body) !== true) {
55+
return $this;
5356
}
5457

55-
return $uri;
58+
$this->body = $body;
59+
60+
return $this;
61+
}
62+
63+
/**
64+
* @return array
65+
*/
66+
public function getBody()
67+
{
68+
if (isset($this->body)) {
69+
return $this->body;
70+
}
71+
if (is_array($this->scrollId)) {
72+
return ['scroll_id' => $this->scrollId];
73+
}
74+
return ['scroll_id' => [$this->scrollId]];
5675
}
5776

5877
/**

src/Elasticsearch/Endpoints/Scroll.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
class Scroll extends AbstractEndpoint
1717
{
18-
private $clear = false;
1918

2019
/**
2120
* @param array $body
@@ -42,9 +41,18 @@ public function getBody()
4241
return $this->body;
4342
}
4443

45-
public function setClearScroll($clear)
44+
/**
45+
* @param $scroll
46+
*
47+
* @return $this
48+
*/
49+
public function setScroll($scroll)
4650
{
47-
$this->clear = $clear;
51+
if (isset($scroll) !== true) {
52+
return $this;
53+
}
54+
55+
$this->body['scroll'] = $scroll;
4856

4957
return $this;
5058
}
@@ -60,7 +68,7 @@ public function setScrollId($scroll_id)
6068
return $this;
6169
}
6270

63-
$this->body = $scroll_id;
71+
$this->body['scroll_id'] = $scroll_id;
6472

6573
return $this;
6674
}
@@ -89,10 +97,6 @@ public function getParamWhitelist()
8997
*/
9098
public function getMethod()
9199
{
92-
if ($this->clear == true) {
93-
return 'DELETE';
94-
}
95-
96100
return 'GET';
97101
}
98102
}

0 commit comments

Comments
 (0)