Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>
<?php
use Elasticsearch\ClientBuilder;
require 'vendor/autoload.php';
$client = ClientBuilder::create()->build();
$params = [
'index' => 'my_index',
'type' => 'my_type',
'id' => 'my_id',
'body' => ['testField' => 'abc']
];
$response = $client->index($params);
print_r($response);
25191;-php 1.php
32467;- 26524;
PHP Fatal error: Uncaught Elasticsearch\Common\Exceptions\NoNodesAvailableException: No alive nodes found in your cluster in /usr/local/src/soft-source/vendor/elasticsearch/elasticsearch/src/Elasticsearch/ConnectionPool/StaticNoPingConnectionPool.php:51
Stack trace:
#0 /usr/local/src/soft-source/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Transport.php(71): Elasticsearch\ConnectionPool\StaticNoPingConnectionPool->nextConnection()
#1 /usr/local/src/soft-source/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Transport.php(89): Elasticsearch\Transport->getConnection()
#2 /usr/local/src/soft-source/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php(228): Elasticsearch\Transport->performRequest('PUT', '/my_index/my_ty...', Array, '{"testField":"a...', Array)
#3 /usr/local/src/soft-source/vendor/react/promise/src/FulfilledPromise.php(25): Elasticsearch\Connections\Connection->Elasticsearch\Connections\{closure}(Array)
#4 /usr/local/src/soft-source/vendor/guzzlehttp/ringphp/src/Future/Compl in /usr/local/src/soft-source/vendor/elasticsearch/elasticsearch/src/Elasticsearch/ConnectionPool/StaticNoPingConnectionPool.php on line 51
Solution: you need to specify the IP and port number of the node
<?php
use Elasticsearch\ClientBuilder;
require 'vendor/autoload.php';
$host=['192.168.1.142:9200'];
$client = ClientBuilder::create()->setHosts($host)->build();
$params = [
'index' => 'my_liming',
'type' => 'my_type',
'id' => 'my_id',
'body' => ['testField' => '123213213c']
];
$response = $client->index($params);
print_r($response);
~
Success:
Array
(
[_index] => my_liming
[_type] => my_type
[_id] => my_id
[_version] => 2
[_shards] => Array
(
[total] => 2
[successful] => 1
[failed] => 0
)
[created] =>
)
Similar Posts:
- The Usage of Numpy.unravel_index() function
- [Solved] reason”: “Root mapping definition has unsupported parameters:
- Compressor detection can only be called on some ……
- [Solved] Elasticsearch Error: “java.lang.IllegalArgumentException: Rejecting mapping update to [xxx] as the final mapping would have more than 1 type: [_doc, log]””
- [Solved] Element-ui Error: [Vue warn]: Invalid prop: type check failed for prop “index”. Expected String with value “1”, got Number with value 1
- [Solved] Elasticsearch:exception [type=search_phase_execution_exception, reason=all shards failed]
- [923]ElasticSearch 7.4.2 Root mapping definition has unsupported parameters
- AttributeError: ‘tuple’ object has no attribute ‘extend’
- Strange frame error caused by incorrect use of flash. Redirect (‘/ path’) in flash
- Oracle Script: How to Solve ‘unusable state index(ORA-01502)’