Skip to content

Get/update fails for item IDs that contain spaces #1278

Closed
@cdlate

Description

@cdlate

Summary

I want to update or get a record having id containing a space using the PHP client library.
Expected: The record having the correct id is returned/updated
Actual: The record is not found

Code snippet of problem

Test dataset:

Kibana dev tools for inserts:

POST test_index/doc/_bulk
{"index": {"_index": "test_index", "_id": "test test"}}
{"field1": "value1"}

This will return data properly:
GET /test_index/_doc/test%20test

$params = [
  'index' => 'test_index',
  //'id'    => 'lp-3MIYB7NAUVXHg5pvt', THIS is working perfectly(no spaces)
  'id'    => 'test test', // this is not working because urlencode does not respect the url encode standard.
  'type' => '_doc'
];

$response = $elasticClient->get($params);

I think the problem is caused by the usage of urlencode instead of rawurlencode in the file AbstractEndPoint, not sure about how many client's methods are affected, not sure if the latest versions are affected, but I highly suspect they are.

See: https://www.php.net/manual/en/function.urldecode.php
See: https://www.php.net/manual/en/function.rawurlencode.php

System details

  • Ubuntu
  • 7.3
  • 6.x//7.x
  • 7.17

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions