'PHP indexing documents in elasticsearch won't accept timestamp
I am inserting a simple document in elasticSearch using PHP. The document is inserted but unfortunately the timestamp is not recorded, and no time stamp is added automatically.
here is a sample code :
<?php
require __DIR__ . '/vendor/autoload.php';
use Elasticsearch\ClientBuilder;
use Carbon\Carbon;
if($_SERVER["REQUEST_METHOD"] == "POST") {
// username and password sent from form
$firstName = $_POST['FirstName'];
$lastName = $_POST['LastName'];
$address = $_POST['Address'];
$hosts = [
'http://localhost:9200'
];
$client = ClientBuilder::create() // Instantiate a new ClientBuilder
->setHosts($hosts) // Set the hosts
->build(); // Build the client object
$myDateTime=Carbon::now();
$params = [
'index' => 'auditsvilles',
'type' => 'logs',
'id' => 'id0001',
'timestamp' => $myDateTime->toIso8601String(),
'body' => ['FirstName' => $firstName, 'LastName' => $lastName]
];
$response = $client->index($params);
print_r($response);
}
?>
I have searched quite extensively, and found someinputs about using Iso8601, but it didn't change.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
