I am using Elastic-PHP API 2.0 to create an index of Word and PDF documents. This normally requires to send a Base64 encoding of the document as JSON to its Mapper attachment plugin.
However, PHP's Base64 generates slashes \
in the encoded string. The JSON which I am trying to construct with this encoding, cannot be parsed by Elastic:
$json =
'{"content" : "'.addslashes(chunk_split(base64_encode($file_contents))).'"}'
I do not want to remove/replace the slashes, as suggested in some Stackoverflow posts, since it may cause problems later with decoding.
How are slashes in Base64 encoding dealt with in such scenarios?