Skip to content

Commit

Permalink
Avoid double slashes in built url
Browse files Browse the repository at this point in the history
# Bug
Using elasticsearch 5.3 and scroll API.
```
$path = '_search/scroll';
$this->elasticsearch->setIndex(null)->setType(null);
$this->elasticsearch->request($path, 'POST', [
    'scroll' => '10m',
    'scroll_id' => $scrollId,
])
```
This was generating the following url: `//_search/scroll` with double slashes causing following error:
```
{
    "error": {
        "root_cause": [
            {
                "type": "string_index_out_of_bounds_exception",
                "reason": "String index out of range: 0"
            }
        ],
        "type": "string_index_out_of_bounds_exception",
        "reason": "String index out of range: 0"
    },
    "status": 500
}
```

# Solution
Avoid adding an extra slash when `$this->index` is null.
  • Loading branch information
KmeCnin authored May 30, 2017
1 parent fbf3f41 commit e24b5f2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/ElasticSearch/Transport/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function setType($type) {
*/
protected function buildUrl($path = false, array $options = array()) {
$isAbsolute = (is_array($path) ? $path[0][0] : $path[0]) === '/';
$url = $isAbsolute ? '' : "/" . $this->index;
$url = $isAbsolute || null === $this->index ? '' : "/" . $this->index;

if ($path && is_array($path) && count($path) > 0)
$url .= "/" . implode("/", array_filter($path));
Expand Down

0 comments on commit e24b5f2

Please sign in to comment.