Since I moved from 2.4 to 5.6, I have an error when using a scroll query :
$query = '{
"scroll" : "1m",
"scroll_id" : "'. $scrollId .'"
}';
$path = '/_search/scroll';
$responseArray = $this->sendQuery($index, $path, Request::GET, $query);
error :
CRITICAL - Uncaught PHP Exception Elastica\Exception\ResponseException: "no such index [index: ]" at /code/vendor/ruflin/elastica/lib/Elastica/Transport/Http.php line 179
Here the initial query I'm using :
$path = 'dataIndex/_search?scroll=1m';
$query = sprintf(
'{
"size" : 500,
"stored_fields": "_source"
}'
);
And how I call my scroll function
$hits = $this->getElasticNextScroll($this->dataIndex, $hits['_scroll_id']);
One of the solution I tried was to send the request with POST but I got another error :
CRITICAL - Uncaught PHP Exception Elastica\Exception\ResponseException: "String index out of range: 0" at /code/vendor/ruflin/elastica/lib/Elastica/Transport/Http.php line 179
EDIT SOLUTION :
the path '/_search/scroll' worked in 2.4 but doesn't work anymore in 5.3. You need to remove the first / : '_search/scroll'
specify what value is passed to $index and what is included in the Request :: GET function
Index {#9208
-originalName: null
-typeCache: []
#_name: "index_data"
#_client: Client {#9234
-indexCache: array:1 [
"index_data" => Index {#9208}
]
-stopwatch: Stopwatch {#157
...
And here the stack error I have :
[1] Elastica\Exception\ResponseException: no such index [index: ] at n/a in /code/vendor/ruflin/elastica/lib/Elastica/Transport/Http.php line 179
at Elastica\Transport\Http->exec(object(Request), array('connection' => array('config' => array('headers' => array(), 'curl' => array()), 'host' => '127.0.0.1', 'port' => '9200', 'logger' => false, 'ssl' => false, 'compression' => false, 'retryOnConflict' => '0', 'enabled' => true))) in /code/vendor/ruflin/elastica/lib/Elastica/Request.php line 193
at Elastica\Request->send() in /code/vendor/ruflin/elastica/lib/Elastica/Client.php line 674
at Elastica\Client->request('/_search/scroll', 'GET', '{ "scroll" : "1m", "scroll_id" : "DnF1ZXJ5VGhlbkZldGNoBAAAAAAAAAPfFnF2VnFBRzFWU0RTaTAwVVZLSl9UU2cAAAAAAAAD3RZxdlZxQUcxVlNEU2kwMFVWS0pfVFNnAAAAAAAAA-AWcXZWcUFHMVZTRFNpMDBVVktKX1RTZwAAAAAAAAPeFnF2VnFBRzFWU0RTaTAwVVZLSl9UU2c=" }', array(), 'application/json') in /code/vendor/friendsofsymfony/elastica-bundle/Elastica/Client.php line 50
at FOS\ElasticaBundle\Elastica\Client->request('/_search/scroll', 'GET', '{ "scroll" : "1m", "scroll_id" : "DnF1ZXJ5VGhlbkZldGNoBAAAAAAAAAPfFnF2VnFBRzFWU0RTaTAwVVZLSl9UU2cAAAAAAAAD3RZxdlZxQUcxVlNEU2kwMFVWS0pfVFNnAAAAAAAAA-AWcXZWcUFHMVZTRFNpMDBVVktKX1RTZwAAAAAAAAPeFnF2VnFBRzFWU0RTaTAwVVZLSl9UU2c=" }') in /code/src/AppBundle/Repository/ElasticSearch/BaseElasticSearchRepository.php line 22
Related
When I try to make a request by PHP Guzzle 7 I am getting the ([2021-10-05 15:50:44] request.CRITICAL: Uncaught PHP Exception InvalidArgumentException: "A 'contents' key is required" at /home/allen/Documents/pim/pim-community-standard/vendor/guzzlehttp/psr7/src/MultipartStream.php line 86 {"exception":"[object] (InvalidArgumentException(code: 0): A 'contents' key is required at /home/allen/Documents/pim/pim-community-standard/vendor/guzzlehttp/psr7/src/MultipartStream.php:86)"} [])
I am trying you upload a picture in Akeneo Pim 5, the endpoint documentation is:
Akeneo Pim 5 - API Documentation
Someone know what I am doing wrong?
Image 01 - Postman
Image 02 - Postman
This request on postman works fine, but I am trying to do it with a guzzle, I already have the first request getting the token.
My Request:
$client2 = new Client();
$file = '/tmp/T_square.jpg';
$url2 = "http://akeneo-pim.local/api/rest/v1/media-files";
$response2 = $client2->request('POST', $url2, [
'headers' => [
'Authorization' => 'Bearer ' . $response->access_token,
'Content-Type' => 'multipart/form-data',
'Accept' => 'application/x-www-form-urlencoded'
],
'multipart' => [
'product' => [
"identifier" => "teste_image",
"attribute" => "picture",
"locale" => null,
"scope" => null
],
'file' => fopen($file, 'r'),
]
]);
I've started writing some code to use SOAP within PHP.
Managed to get my code to login and authenticate, which is a start!
I initially had the following code :
$params = array(
"Parcels" => 1,
"RecipientAddress" => "123 Any Street, Any Town, Anywhere",
"RecipientName" => "Joe Bloggs",
"CollectionDate" => "2019-11-11",
);
// Invoke WS method (Function1) with the request params
$response = $client->__soapCall("GetAvailableServices", array($params));
// Print WS response
var_dump($response);
Which returned the following message :
Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Client] Missing Recipient Address Element 'RecipientName' in /home/thisone/public_html/despatchbayservices.php:17 Stack trace: #0 /home/thisone/public_html/despatchbayservices.php(17): SoapClient->__soapCall('GetAvailableSer...', Array) #1 {main} thrown in /home/thisone/public_html/despatchbayservices.php on line 17
I've tried changing the code to :
$params = array(
"Parcels" => 1,
"RecipientAddress" => array(
"RecipientName" => "Joe Bloggs",
),
"CollectionDate" => "2019-11-11",
);
// Invoke WS method (Function1) with the request params
$response = $client->__soapCall("GetAvailableServices", array($params));
// Print WS response
var_dump($response);
Which returned this :
Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: object has no 'RecipientAddress' property in /home/thisone/public_html/despatchbayservices.php:18 Stack trace: #0 /home/thisone/public_html/despatchbayservices.php(18): SoapClient->__soapCall('GetAvailableSer...', Array) #1 {main} thrown in /home/thisone/public_html/despatchbayservices.php on line 18
I'm sure I'm doing something really stupid but I just cant see it - any help massively appreciated!
Sussed it - thanks to Don't Panic for pointing me toward the WDSL.
For reference the correct/working code is :
$params = array(
"Parcels" => array(
"ParcelType" => array(
"Weight" => 5,
"Length" => 5,
"Width" => 5,
"Height"=> 5,
)
),
"RecipientAddress" => array(
"RecipientName" => "Joe Bloggs",
"RecipientAddress" => array(
"CompanyName" => "My Company",
"Street" => "123 Any Street",
"Locality" => "Anywhere",
"TownCity" => "Any Town",
"County" => "Somewhere",
"PostalCode" => "TS23 4EA",
"CountryCode" => "GB",
)
),
"CollectionDate" => "2019-11-11",
);
// Invoke WS method (Function1) with the request params
$response = $client->__soapCall("GetAvailableServices", array($params));
I have an ajax request in my application which returns a json object:
public function getCustomerTransactions($customerid = null)
{
$this->viewBuilder()->setLayout(false);
$this->autoRender = false;
$selectedCustomerCompany = $this->request->getData('customer');
$selectedCustomer = TableRegistry::get('Customers')->find('all', [
'conditions' => ['Customers.company LIKE '=> $selectedCustomerCompany]
])->first();
$customerTransactions = TableRegistry::get('Transactions')->find('all', [
'conditions' => ['customer_id '=> $selectedCustomer->id, 'transaction_type_id ' => 1, 'invoice_id IS NULL']//,
]);
echo json_encode($customerTransactions);
}
But instead of 19 transactions it returns 11 and then this message (I can see it from network tab) :
Warning (512): Unable to emit headers. Headers sent in
file=/var/www/vhosts/domain/public_html/demo/app/src/Controller/InvoicesController.php line=508 [CORE/src/Http/ResponseEmitter.php, line
48]Code Context
0000BB">
style="color: #007700">if (
0000BB">Configure::read
007700">('debug')) {
class="code-highlight">
0000BB"> trigger_error
style="color: #007700">(
0000BB">$message, E_USER_WARNING);
style="color:
007700">} else {
none;">$response = object(Cake\Http\Response) {
'status' => (int) 200, 'contentType' =>
'text/html', 'headers' => [
'Content-Type' => [ [maximum depth reached] ] ],
'file' => null, 'fileRange' => [],
'cookies' => object(Cake\Http\Cookie\CookieCollection)
{}, 'cacheDirectives' => [], 'body' =>
''
} $maxBufferLength = (int) 8192 $file =
'/var/www/vhosts/domain/public_html/demo/app/src/Controller/InvoicesController.php'
$line = (int) 508 $message = 'Unable to emit headers. Headers
sent in
file=/var/www/vhosts/domain/public_html/demo/app/src/Controller/InvoicesController.php line=508'Cake\Http\ResponseEmitter::emit() -
CORE/src/Http/ResponseEmitter.php, line 48 Cake\Http\Server::emit() -
CORE/src/Http/Server.php, line 141
So I get this javascript error :
Uncaught SyntaxError: Unexpected token < in JSON at position 6922
Because there is html code in the response.
I tried to set the depth option in json_encode but I get the same results.
UPDATE
I ended up using:
if($this->request->is('ajax')){
Configure::write('debug', 0);
}
In the controller. But is this the correct way?
I am trying to follow this tutorial, and I need to do it in PHP, so I have to use Elasticsearch-php. In this particular step, I am trying to set up a mapping for elasticsearch and also bulk index data from a .json file. So I looked into examples here and [here][3], and following is my code.
The problem is taht it gives me
Elasticsearch PHP client created successfully!
Fatal error: Uncaught Elasticsearch\Common\Exceptions\BadRequest400Exception: {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Action/metadata line [1] contains an unknown parameter [dynamic]"}],"type":"illegal_argument_exception","reason":"Action/metadata line [1] contains an unknown parameter [dynamic]"},"status":400} in /var/www/html/Tests/Test/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:610 Stack trace: #0 /var/www/html/Tests/Test/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php(273): Elasticsearch\Connections\Connection->process4xxError(Array, Array, Array) #1 /var/www/html/Tests/Test/vendor/react/promise/src/FulfilledPromise.php(25): Elasticsearch\Connections\Connection->Elasticsearch\Connections\{closure}(Array) #2 /var/www/html/Tests/Test/vendor/guzzlehttp/ringphp/src/Future/CompletedFutureValue.php(55): React\Promise\FulfilledPromise->then(Object(Closure), NULL, NULL) #3 /var/www/html/Tests/Test/vendor/guzzlehttp/ringphp/src/ in /var/www/html/Tests/Test/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php on line 610
and when I comment out the line "dynamic" => "false", I get
Elasticsearch PHP client created successfully!
Fatal error: Uncaught Elasticsearch\Common\Exceptions\BadRequest400Exception: {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Malformed action/metadata line [1], expected a simple value for field [properties] but found [START_OBJECT]"}],"type":"illegal_argument_exception","reason":"Malformed action/metadata line [1], expected a simple value for field [properties] but found [START_OBJECT]"},"status":400} in /var/www/html/Tests/Test/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:610 Stack trace: #0 /var/www/html/Tests/Test/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php(273): Elasticsearch\Connections\Connection->process4xxError(Array, Array, Array) #1 /var/www/html/Tests/Test/vendor/react/promise/src/FulfilledPromise.php(25): Elasticsearch\Connections\Connection->Elasticsearch\Connections\{closure}(Array) #2 /var/www/html/Tests/Test/vendor/guzzlehttp/ringphp/src/Future/CompletedFutureValue.php(55): React\Promise\FulfilledPromise->then(O in /var/www/html/Tests/Test/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php on line 610
What am I missing? How should I fix this?
<?php
require_once("vendor/autoload.php");
use Elasticsearch\ClientBuilder;
$esClient = ClientBuilder::create()->build();
echo "Elasticsearch PHP client created successfully!<br>";//check
$indexParams = array();
$indexParams['index'] = "test_packets_index";
$indexParams['type'] = "testPacketsType";
$indexParams['body'] = [
'mappings' => [
"testPacketsType" => [
//"dynamic" => "false",
"properties" => [
"timestamp" => [
"type" => "date"
],
"layers" => [
"properties" => [
"ip" => [
"properties" => [
"ip_ip_src" => [
"type" => "ip"
],
"ip_ip_dst" => [
"type" => "ip"
]
]
]
]
]
]
]
]
];
$jsonFileHandle = fopen("packets.json", "r");
if ($jsonFileHandle) {
while ( ($line = fgets($jsonFileHandle)) !== FALSE ) {
if ( !($line == "") ) {
$indexParams['body'][] = json_decode($line, true);
}
}
}
fclose($jsonFileHandle);
#print_r($indexParams['body']);//check
$indexingResponse = $esClient->bulk($indexParams);
echo "Result: "; print_r($indexingResponse); echo "<br>";//check
?>
[3]: https : //www.elastic.co/guide/en/elasticsearch/client/php-api/current/_indexing_documents.html
I am trying to create a spatial database with neo4j 3.0.2 and neo4j-spatial for 3.0.2. I have installed the plugin and I have checked that the plugin is running with cURL curl -v http://neo4j:neo4j#localhost:7474/db/data/ which outputs following:
{
"extensions" : {
"SpatialPlugin" : {
"addSimplePointLayer" : "http://localhost:7474/db/data/ext/SpatialPlugin/graphdb/addSimplePointLayer",
"addNodesToLayer" : "http://localhost:7474/db/data/ext/SpatialPlugin/graphdb/addNodesToLayer",
"findClosestGeometries" : "http://localhost:7474/db/data/ext/SpatialPlugin/graphdb/findClosestGeometries",
"addGeometryWKTToLayer" : "http://localhost:7474/db/data/ext/SpatialPlugin/graphdb/addGeometryWKTToLayer",
"findGeometriesWithinDistance" : "http://localhost:7474/db/data/ext/SpatialPlugin/graphdb/findGeometriesWithinDistance",
"addEditableLayer" : "http://localhost:7474/db/data/ext/SpatialPlugin/graphdb/addEditableLayer",
"addCQLDynamicLayer" : "http://localhost:7474/db/data/ext/SpatialPlugin/graphdb/addCQLDynamicLayer",
"addNodeToLayer" : "http://localhost:7474/db/data/ext/SpatialPlugin/graphdb/addNodeToLayer",
"getLayer" : "http://localhost:7474/db/data/ext/SpatialPlugin/graphdb/getLayer",
"findGeometriesInBBox" : "http://localhost:7474/db/data/ext/SpatialPlugin/graphdb/findGeometriesInBBox",
"updateGeometryFromWKT" : "http://localhost:7474/db/data/ext/SpatialPlugin/graphdb/updateGeometryFromWKT",
"findGeometriesIntersectingBBox" : "http://localhost:7474/db/data/ext/SpatialPlugin/graphdb/findGeometriesIntersectingBBox"
}
},
"node" : "http://localhost:7474/db/data/node",
"relationship" : "http://localhost:7474/db/data/relationship",
"node_index" : "http://localhost:7474/db/data/index/node",
"relationship_index" : "http://localhost:7474/db/data/index/relationship",
"extensions_info" : "http://localhost:7474/db/data/ext",
"relationship_types" : "http://localhost:7474/db/data/relationship/types",
"batch" : "http://localhost:7474/db/data/batch",
"cypher" : "http://localhost:7474/db/data/cypher",
"indexes" : "http://localhost:7474/db/data/schema/index",
"constraints" : "http://localhost:7474/db/data/schema/constraint",
"transaction" : "http://localhost:7474/db/data/transaction",
"node_labels" : "http://localhost:7474/db/data/labels",
"neo4j_version" : "3.0.2"
* Connection #0 to host localhost left intact
}* Closing connection #0
Now I can create a new simplePointLayer:
// define entity manager
$client = $this->get('neo4j.spatial_manager')->getClient();
// 1. Create a pointlayer
$request = $client->request('POST',
'/db/data/ext/SpatialPlugin/graphdb/addSimplePointLayer',
[
'json' => [
'layer' => 'geom',
'lat' => 'lat',
'lon' => 'lon',
],
]
);
var_dump($request);
This creates the spatial root node with the rTree. But when I now want to create a spatial index with following:
// 2. Create a spatial index
$request = $client->request('POST',
'/db/data/index/node/',
[
'json' => [
'name' => 'geom',
'config' => [
'provider' => 'spatial',
'geometry_type' => 'point',
'lat' => 'lat',
'lon' => 'lon',
],
],
]
);
var_dump($request);
I am confronted with the error-message:
"message" : "No index provider 'spatial' found.
What am I doing wrong? I have checked a lot of forums and so on, but the answer always seems to be to install the spatial plugin, which I have and it seems to be working according to the first output.
EDIT 15.06.2016
Whats weird is that I can add nodes to the rTree:
// Create a node with spatial data
$json = [
'team' => 'REDBLUE',
'name' => 'TEST',
'lat' => 25.121075,
'lon' => 89.990630,
];
$response = $client->request('POST',
'/db/data/node',
[
'json' => $json
]
);
$node = json_decode($response->getBody(), true)['self'];
// Add the node to the layer
$response = $client->request('POST',
'/db/data/ext/SpatialPlugin/graphdb/addNodeToLayer',
[
'json' => [
'layer' => 'geom',
'node' => $node,
],
]
);
$data = json_decode($response->getBody(), true);
var_dump($data);
And I can query the nodes through REST:
$request = $client->request('POST',
'/db/data/ext/SpatialPlugin/graphdb/findGeometriesWithinDistance',
[
'json' => [
'layer' => 'geom',
'pointX' => 89.99506,
'pointY' => 25.121260,
'distanceInKm' => 10,
],
]
);
$data = json_decode($request->getBody(), true);
var_dump($data);
But why is it not letting me create an index? Or does it do the indexing automatically? And if so, how can I query using CYPHER (in the web console for example)?
Any help would be appreciated! Cheers
The index provider was removed (back then it was the only means to provide integration with Cypher), in favor of user defined procedures for Spatial.
see: https://github.com/neo4j-contrib/spatial/blob/master/src/test/java/org/neo4j/gis/spatial/procedures/SpatialProceduresTest.java#L113
As this is a new major release (for 3.0) we found it sensible to remove the index provider.