elastic / elasticsearch-php

Official PHP client for Elasticsearch.
https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html
MIT License
5.25k stars 964 forks source link

Index a document Error "reason":"Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes" #1338

Closed ticfinack closed 1 year ago

ticfinack commented 1 year ago

Environment:

I created a variable containing the body of the $params[] for the document that I wish to index. echo($variable); // as seen from chrome view-source page   | 'uid'=>'33345',   | 'msgn'=>'33345',   | 'msglist'=>'0',   | 'header-from'=>'Dark Reading Webinar <DarkReading@am.amtechwebresources.com>',   | 'header-to'=>'email@domain.com',   | 'header-reply_to'=>'Dark Reading <emailcontact@ubm.com>',   | 'subject'=>'State of DDoS: Mid-Year Threat Report \| July 19',   | 'header-message_id'=>'8078a7a6cf3a45fba53440386e827a2c@2150',   | 'header-date'=>'2023-07-01T08:37:28-04:00',   | 'header-return_path'=>'<noreply@am.amtechwebresources.com>',   | 'header-delivered_to'=>'email@domain.com',   | 'header-received'=>'from mail.edgeaspect.com ([10.1.217.7]) by dovecot.some.domain.com with LMTP id Y+dJNvG8oWSpBgAAkzG9Ng (envelope-from <noreply@am.amtechwebresources.com>) for <email@domain.com>',   | 'header-dkim_signature'=>'v=1',   | 'header-authentication_results'=>'some.domain.com',   | 'header-x_binding'=>'2150',   | 'header-x_elqsiteid'=>'2150',   | 'header-x_elqpod'=>'0x3BC0F1C4E8C62358C67C33A17D924B7F1CC164F157C9649CB0F6FD597FB1CA9C',   | 'header-x_cid'=>'49012-117134',   | 'header-list_unsubscribe'=>'=?utf-8?q?=3Cmailto=3Aspamproc=40fbl=2Een25=2Ecom=3Fsubject=3DListUnsub=5F2150=5F8078a7a6?= =?utf-8?q?cf3a45fba53440386e827a2c=3E=2C?= =?utf-8?q?_=3Chttp=3A=2F=2Fapp=2Ereg=2Etechweb=2Ecom=2Fe=2Fu=3Fs=3D2150&elq=3D8078a7a6cf3a45fba5?= =?utf-8?q?3440386e827a2c&t=3D17=3E?=',   | 'header-mime_version'=>'1.0',   | 'header-content_type'=>'multipart/alternative',   | 'fromaddress'=>'Dark Reading Webinar <DarkReading@am.amtechwebresources.com>',   | 'header-reply_toaddress'=>'Dark Reading <emailcontact@ubm.com>',   | 'toaddress'=>'email@domain.com',   | 'header-a'=>'rsa-sha256',   | 'header-c'=>'relaxed/relaxed',   | 'header-s'=>'dk2016',   | 'header-d'=>'am.amtechwebresources.com',   | 'header-h'=>'Message-ID:List-Unsubscribe:From:Reply-To:To:Subject:Date:MIME-Version: Content-Type',   | 'header-i'=>'DarkReading@am.amtechwebresources.com',   | 'header-bh'=>'xnsLKcwuL76HjHoqD3XceuLlkZto/i6NKw/H9CwatO4=',   | 'header-b'=>'jVdXZLYSYh0iVmKZlM0M8O2RxSfUbRcmAQxiwOvsl53s8SoNIE/X/68OwUcr3ghJSBIjnPX9Ypu4 PvnUBa2uaeIHeGjQePkSaFv5EAQN5HToT3OQRUNkUUdS2N/EVdSwwBRW0EX8BK3f+qbBlsqZnHk8 jW7QLtM/oYoNO//NfI4=',   | 'header-dkim'=>'pass (1024-bit key',   | 'header-secure) header.d'=>'am.amtechwebresources.com header.i=DarkReading@am.amtechwebresources.com header.a=rsa-sha256 header.s=dk2016 header.b=jVdXZLYS',   | 'header-boundary'=>'=-QJTwoI8huAPN5zBjEB6EKg==',

When I use the variable in the body of the $params[], as seen below, I get the error "Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes". $params = [ 'index' => "mailbox-$email", 'body' => [$variable] ]; try { //$response = $elastic->index($params); } catch (ClientResponseException $e) { echo "<pre>"; print_r($e); echo "</pre>"; } catch (ServerResponseException $e) { echo "<pre>"; print_r($e); echo "</pre>"; } catch (Exception $e) { echo "<pre>"; print_r($e); echo "</pre>"; }

However, when I echo the $variable and copy/paste the contents of the chrome view-source page to the body of the $params[] as seen below, the index succeeds. $params = [ 'index' => "mailbox-$email", 'body' => [ 'uid'=>'33345', ................................. header.a=rsa-sha256 header.s=dk2016 header.b=jVdXZLYS', 'header-boundary'=>'=-QJTwoI8huAPN5zBjEB6EKg==',] ]; try { $response = $elastic->index($params); } catch (ClientResponseException $e) { echo "<pre>"; print_r($e); echo "</pre>"; } catch (ServerResponseException $e) { echo "<pre>"; print_r($e); echo "</pre>"; } catch (Exception $e) { echo "<pre>"; print_r($e); echo "</pre>"; }

I cannot find the issue and therefore cannot figure out how to format the string/array so that the $params[] body will accept my variable. Please help, I've been trying different string and array manipulations for over 20 hours now.

ticfinack commented 1 year ago

I'm not sure why the code block didn't handle the new lines the same, but here's what I see in a screenshot. image

ticfinack commented 1 year ago

Also, here's the rest of the error and a different set of string data for the $variable, in case that was a potential question.

echo $variable; 'foldername'=>'INBOX',  'folder_full_name'=>'INBOX',  'folder_delimiter'=>'/',

Full error:    | <pre>Elastic\Elasticsearch\Exception\ServerResponseException Object   | (   | [message:protected] => 500 Internal Server Error: {"error":{"root_cause":[{"type":"not_x_content_exception","reason":"Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"}],"type":"not_x_content_exception","reason":"Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"},"status":500}   | [string:Exception:private] =>   | [code:protected] => 500   | [file:protected] => /var/www/html/vendor/elasticsearch/elasticsearch/src/Response/Elasticsearch.php   | [line:protected] => 71   | [trace:Exception:private] => Array   | (   | [0] => Array   | (   | [file] => /var/www/html/vendor/elasticsearch/elasticsearch/src/Client.php   | [line] => 172   | [function] => setResponse   | [class] => Elastic\Elasticsearch\Response\Elasticsearch   | [type] => ->   | [args] => Array   | (   | [0] => GuzzleHttp\Psr7\Response Object   | (   | [reasonPhrase:GuzzleHttp\Psr7\Response:private] => Internal Server Error   | [statusCode:GuzzleHttp\Psr7\Response:private] => 500   | [headers:GuzzleHttp\Psr7\Response:private] => Array   | (   | [X-elastic-product] => Array   | (   | [0] => Elasticsearch   | )   |     | [content-type] => Array   | (   | [0] => application/vnd.elasticsearch+json;compatible-with=8   | )   |     | [content-length] => Array   | (   | [0] => 313   | )   |     | )   |     | [headerNames:GuzzleHttp\Psr7\Response:private] => Array   | (   | [x-elastic-product] => X-elastic-product   | [content-type] => content-type   | [content-length] => content-length   | )   |     | [protocol:GuzzleHttp\Psr7\Response:private] => 1.1   | [stream:GuzzleHttp\Psr7\Response:private] => GuzzleHttp\Psr7\Stream Object   | (   | [stream:GuzzleHttp\Psr7\Stream:private] => Resource id #165   | [size:GuzzleHttp\Psr7\Stream:private] =>   | [seekable:GuzzleHttp\Psr7\Stream:private] => 1   | [readable:GuzzleHttp\Psr7\Stream:private] => 1   | [writable:GuzzleHttp\Psr7\Stream:private] => 1   | [uri:GuzzleHttp\Psr7\Stream:private] => php://temp   | [customMetadata:GuzzleHttp\Psr7\Stream:private] => Array   | (   | )   |     | )   |     | )   |     | [1] => 1   | )   |     | )   |     | [1] => Array   | (   | [file] => /var/www/html/vendor/elasticsearch/elasticsearch/src/Traits/ClientEndpointsTrait.php   | [line] => 905   | [function] => sendRequest   | [class] => Elastic\Elasticsearch\Client   | [type] => ->   | [args] => Array   | (   | [0] => GuzzleHttp\Psr7\Request Object   | (   | [method:GuzzleHttp\Psr7\Request:private] => POST   | [requestTarget:GuzzleHttp\Psr7\Request:private] =>   | [uri:GuzzleHttp\Psr7\Request:private] => GuzzleHttp\Psr7\Uri Object   | (   | [scheme:GuzzleHttp\Psr7\Uri:private] =>   | [userInfo:GuzzleHttp\Psr7\Uri:private] =>   | [host:GuzzleHttp\Psr7\Uri:private] =>   | [port:GuzzleHttp\Psr7\Uri:private] =>   | [path:GuzzleHttp\Psr7\Uri:private] => /mailbox-twilliams%40edgeaspect.com/_doc   | [query:GuzzleHttp\Psr7\Uri:private] =>   | [fragment:GuzzleHttp\Psr7\Uri:private] =>   | [composedComponents:GuzzleHttp\Psr7\Uri:private] =>   | )   |     | [headers:GuzzleHttp\Psr7\Request:private] => Array   | (   | [Accept] => Array   | (   | [0] => application/vnd.elasticsearch+json; compatible-with=8   | )   |     | [Content-Type] => Array   | (   | [0] => application/vnd.elasticsearch+json; compatible-with=8   | )   |     | )   |     | [headerNames:GuzzleHttp\Psr7\Request:private] => Array   | (   | [accept] => Accept   | [content-type] => Content-Type   | )   |     | [protocol:GuzzleHttp\Psr7\Request:private] => 1.1   | [stream:GuzzleHttp\Psr7\Request:private] => GuzzleHttp\Psr7\Stream Object   | (   | [stream:GuzzleHttp\Psr7\Stream:private] => Resource id #154   | [size:GuzzleHttp\Psr7\Stream:private] => 109   | [seekable:GuzzleHttp\Psr7\Stream:private] => 1   | [readable:GuzzleHttp\Psr7\Stream:private] => 1   | [writable:GuzzleHttp\Psr7\Stream:private] => 1   | [uri:GuzzleHttp\Psr7\Stream:private] => php://temp   | [customMetadata:GuzzleHttp\Psr7\Stream:private] => Array   | (   | )   |     | )   |     | )   |     | )   |     | )   |     | [2] => Array   | (   | [file] => /var/www/html/elasticController.php   | [line] => 314   | [function] => index   | [class] => Elastic\Elasticsearch\Client   | [type] => ->   | [args] => Array   | (   | [0] => Array   | (   | [index] => mailbox-twilliams@edgeaspect.com   | [body] => Array   | (   | [0] => 'folderpath'=>'INBOX',   | 'foldername'=>'INBOX',   | 'folder_full_name'=>'INBOX',   | 'folder_delimiter'=>'/',   |     | )   |     | )   |     | )   |     | )   |     | )   |     | [previous:Exception:private] =>   | [response:protected] => GuzzleHttp\Psr7\Response Object   | (   | [reasonPhrase:GuzzleHttp\Psr7\Response:private] => Internal Server Error   | [statusCode:GuzzleHttp\Psr7\Response:private] => 500   | [headers:GuzzleHttp\Psr7\Response:private] => Array   | (   | [X-elastic-product] => Array   | (   | [0] => Elasticsearch   | )   |     | [content-type] => Array   | (   | [0] => application/vnd.elasticsearch+json;compatible-with=8   | )   |     | [content-length] => Array   | (   | [0] => 313   | )   |     | )   |     | [headerNames:GuzzleHttp\Psr7\Response:private] => Array   | (   | [x-elastic-product] => X-elastic-product   | [content-type] => content-type   | [content-length] => content-length   | )   |     | [protocol:GuzzleHttp\Psr7\Response:private] => 1.1   | [stream:GuzzleHttp\Psr7\Response:private] => GuzzleHttp\Psr7\Stream Object   | (   | [stream:GuzzleHttp\Psr7\Stream:private] => Resource id #165   | [size:GuzzleHttp\Psr7\Stream:private] =>   | [seekable:GuzzleHttp\Psr7\Stream:private] => 1   | [readable:GuzzleHttp\Psr7\Stream:private] => 1   | [writable:GuzzleHttp\Psr7\Stream:private] => 1   | [uri:GuzzleHttp\Psr7\Stream:private] => php://temp   | [customMetadata:GuzzleHttp\Psr7\Stream:private] => Array   | (   | )   |     | )   |     | )   |     | )   | </pre>

ticfinack commented 1 year ago

Found a solution that works, when using a variable make it an associative array and it'll function as expected. Ensure that the variable is of the gettype($variable) == array and the format of the contents is [key]=>[value] and NOT [0] 'key'=>'value'... Closing.