# Trouble while using PHP to extract data from Elasticsearch, Logstash

**URL:** <https://discuss.elastic.co/t/trouble-while-using-php-to-extract-data-from-elasticsearch-logstash/186674>\
**Category:** Elasticsearch\
**Created:** [June 20, 2019, 12:12pm UTC](https://discuss.elastic.co/t/trouble-while-using-php-to-extract-data-from-elasticsearch-logstash/186674 "2019-06-20T12:12:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShashankAC](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@ShashankAC](https://discuss.elastic.co/u/ShashankAC)\
**Post date:** [June 20, 2019, 12:12pm UTC](https://discuss.elastic.co/t/trouble-while-using-php-to-extract-data-from-elasticsearch-logstash/186674/1 "2019-06-20T12:12:04Z")

</div>

Hi there,

I am new to ELK, I first tried to migrate data from MySQL to Elasticsearch using python using the tutorial in the below link. It worked.

> **[Exporting Pandas Data to Elasticsearch](https://towardsdatascience.com/exporting-pandas-data-to-elasticsearch-724aa4dd8f62)**
>
> How to send your dataframe rows to an elasticsearch database

Later, I tried to do it with Logstash, the data is migrated, but my PHP code is running into an error (displayed in the browser) as shown below.

**Fatal error** : Uncaught Elasticsearch\Common\Exceptions\UnexpectedValueException: "id" is not a valid parameter. Allowed parameters are "\_source", "\_source\_exclude", "\_source\_include", "allow\_no\_indices", "analyze\_wildcard", "analyzer", "batched\_reduce\_size", "client", "custom", "default\_operator", "df", "docvalue\_fields", "expand\_wildcards", "explain", "fielddata\_fields", "filter\_path", "filter\_path", "from", "human", "ignore\_unavailable", "indices\_boost", "lenient", "lowercase\_expanded\_terms", "preference", "q", "query\_cache", "request\_cache", "routing", "scroll", "search\_type", "size", "slice", "sort", "source", "stats", "stored\_fields", "suggest\_field", "suggest\_mode", "suggest\_size", "suggest\_text", "terminate\_after", "timeout", "typed\_keys", "version" in /var/www/html/elastic\_php/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Endpoints/AbstractEndpoint.php:237 Stack trace: #0 /var/www/html/elastic\_php/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Endpoints/AbstractEndpoint.php(74): Elasticsearch\Endpoints in **/var/www/html/elastic\_php/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Endpoints/AbstractEndpoint.php** on line **237**

Below is the Logstash.config file.

input {  
jdbc {  
id =\> "stateQuality"  
jdbc\_connection\_string =\> "jdbc:mysql://localhost/telecom1"  
# The user we wish to execute our statement as  
jdbc\_user =\> "xxxxx"  
jdbc\_password =\> "xxxxxxx"  
# The path to our downloaded jdbc driver  
jdbc\_driver\_library =\> "/usr/share/java/mysql-connector-java-8.0.16.jar"  
jdbc\_driver\_class =\> "com.mysql.jdbc.Driver"  
# our query  
statement =\> "SELECT \* FROM state\_quality"  
}  
}

output {  
stdout { codec =\> json\_lines }  
elasticsearch {  
hosts =\> "localhost:9200"  
index =\> "state\_index"  
id =\> "%{id}"  
}  
}

I tried with "document\_id" in the output part of the file, it didn't work

I tried with "\_id" it didn't work.

I tried with just "id" it still didn't work.

Below is my PHP code

\<?php //use Elasticsearch\ClientBuilder; require 'vendor/autoload.php'; $client = Elasticsearch\ClientBuilder::create()-\>build(); // if ($client) { // echo 'connected'; // } $params = ['index' =\> 'state\_index', 'type' =\> '\_doc', 'id' =\> 'new\_user',]; $response = $client-\>get($params); $response = $client-\>search($params); $hits = count($response['hits']['hits']); echo $hits; The tutorial I have linked to says the \_id some kind of unique id for elasticsearch, I am not sure exactly what it is and how to set that in the logstash.config file and how to address that in PHP. Kindly provide some help.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 18, 2019, 12:12pm UTC](https://discuss.elastic.co/t/trouble-while-using-php-to-extract-data-from-elasticsearch-logstash/186674/2 "2019-07-18T12:12:12Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
