# Bulk index "Failed to derive xcontent" error

**URL:** https://discuss.elastic.co/t/bulk-index-failed-to-derive-xcontent-error/9924
**Category:** Elasticsearch
**Created:** [December 3, 2012, 9:04pm UTC](https://discuss.elastic.co/t/bulk-index-failed-to-derive-xcontent-error/9924 "2012-12-03T21:04:16Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![drichar](https://avatars.discourse-cdn.com/v4/letter/d/f4b2a3/32.png) [@drichar](https://discuss.elastic.co/u/drichar)
#### Post date: [December 3, 2012, 9:04pm UTC](https://discuss.elastic.co/t/bulk-index-failed-to-derive-xcontent-error/9924/1 "2012-12-03T21:04:16Z")

</div>

Hi all! I'm still fairly new to elasticsearch. So far so good until I am  
now attempting to use the bulk index API.

I have a PHP script pulling data from an Oracle db, creating a  
'bulkIndex.data' file, and I'm trying to index it using:

$cmd = "curl -XPUT [http://localhost:9200/\_bulk](http://localhost:9200/_bulk) --data-binary  
@bulkIndex.data";  
exec($cmd);

I'm getting an error:

{"error":"Failed to derive xcontent from org.elasticsearch.common.bytes.ChannelBufferBytesReference@77256a74"}

Here is a sample of the contents of my file:

$ cat bulkIndex.data  
{ "index" : {"\_index":"test","\_type":"mo","\_id":"1"} }  
{"CDR\_ID":"4894","MSISDN":"14169988312","SHORT\_CODE":"44446","APP\_ID":"1158","OPERATOR\_ID":"0","SHORT\_MESSAGE":"Test1","SMS\_ID":"19f1eb3d1b5579781ba1c051d8d6739e","DATE\_TIMESTAMP":"20120727131710","INSERT\_TIMESTAMP":"20121129212256"}  
{ "index" : {"\_index":"test","\_type":"mo","\_id":"2"} }  
{"CDR\_ID":"4895","MSISDN":"17059380753","SHORT\_CODE":"41128","APP\_ID":"1038","OPERATOR\_ID":"0","SHORT\_MESSAGE":"Test2","SMS\_ID":"d8d849f760623f1720ef08634b3867b4","DATE\_TIMESTAMP":"20120727131804","INSERT\_TIMESTAMP":"20121129212256"}  
...

{ "index" : {"\_index":"test","\_type":"mt","\_id":"32030"} }  
{"CDR\_ID":"56163","MSISDN":"9026290583","SHORT\_CODE":"41225","APP\_ID":"1038","OPERATOR\_ID":"0","SHORT\_MESSAGE":"Test32030","SMS\_ID":"67709e2f908c072112db7f1c173af0b9","DATE\_TIMESTAMP":"20120731215731","INSERT\_TIMESTAMP":"20121203172327"}

$

Why am I getting this error? Any help would be greatly appreciated. Thank  
you!

--

---

<div class="post-metadata">

### Author: ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)
#### Post date: [December 4, 2012, 3:09pm UTC](https://discuss.elastic.co/t/bulk-index-failed-to-derive-xcontent-error/9924/2 "2012-12-04T15:09:29Z")

</div>

Hello Doug,

That's strange, because it works for me, with the data you provided:

> <https://gist.github.com/radu-gheorghe/4204760>

Can you share a script and an input file where the problem is reproducible?

Anyway, I think the way to go with PHP and Elasticsearch is by using the  
Elastica[0] or Elasticsearch[1]. Although I've never used them, AFAIK at  
least Elastica supports bulks. So you can write docs directly, without  
needing to write them to a file.

Another cool thing that might fit your usecase is the JDBC river[2]. This  
would enable Elasticsearch to automatically pull data from your DB.

[0] [GitHub - ruflin/Elastica: Elastica is a PHP client for elasticsearch](https://github.com/ruflin/Elastica)  
[1] [GitHub - nervetattoo/elasticsearch: Simple PHP client for ElasticSearch](https://github.com/nervetattoo/elasticsearch)  
[2] [GitHub - jprante/elasticsearch-jdbc: JDBC importer for Elasticsearch](https://github.com/jprante/elasticsearch-river-jdbc)

## Best regards, Radu

[http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene

On Mon, Dec 3, 2012 at 11:04 PM, Doug Richar [drichar@gmail.com](mailto:drichar@gmail.com) wrote:

> Hi all! I'm still fairly new to elasticsearch. So far so good until I am  
> now attempting to use the bulk index API.
> 
> I have a PHP script pulling data from an Oracle db, creating a  
> 'bulkIndex.data' file, and I'm trying to index it using:
> 
> $cmd = "curl -XPUT [http://localhost:9200/\_bulk](http://localhost:9200/_bulk) --data-binary  
> @bulkIndex.data";  
> exec($cmd);
> 
> I'm getting an error:
> 
> {"error":"Failed to derive xcontent from org.elasticsearch.common.bytes.ChannelBufferBytesReference@77256a74"}
> 
> Here is a sample of the contents of my file:
> 
> $ cat bulkIndex.data  
> { "index" : {"\_index":"test","\_type":"mo","\_id":"1"} }  
> {"CDR\_ID":"4894","MSISDN":"14169988312","SHORT\_CODE":"44446","APP\_ID":"1158","OPERATOR\_ID":"0","SHORT\_MESSAGE":"Test1","SMS\_ID":"19f1eb3d1b5579781ba1c051d8d6739e","DATE\_TIMESTAMP":"20120727131710","INSERT\_TIMESTAMP":"20121129212256"}  
> { "index" : {"\_index":"test","\_type":"mo","\_id":"2"} }  
> {"CDR\_ID":"4895","MSISDN":"17059380753","SHORT\_CODE":"41128","APP\_ID":"1038","OPERATOR\_ID":"0","SHORT\_MESSAGE":"Test2","SMS\_ID":"d8d849f760623f1720ef08634b3867b4","DATE\_TIMESTAMP":"20120727131804","INSERT\_TIMESTAMP":"20121129212256"}  
> ...
> 
> { "index" : {"\_index":"test","\_type":"mt","\_id":"32030"} }  
> {"CDR\_ID":"56163","MSISDN":"9026290583","SHORT\_CODE":"41225","APP\_ID":"1038","OPERATOR\_ID":"0","SHORT\_MESSAGE":"Test32030","SMS\_ID":"67709e2f908c072112db7f1c173af0b9","DATE\_TIMESTAMP":"20120731215731","INSERT\_TIMESTAMP":"20121203172327"}
> 
> $
> 
> Why am I getting this error? Any help would be greatly appreciated. Thank  
> you!
> 
> --

--

---

<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 6, 2017, 3:01am UTC](https://discuss.elastic.co/t/bulk-index-failed-to-derive-xcontent-error/9924/3 "2017-07-06T03:01:34Z")

</div>


