# Source document is not storing as mentioned in java api

**URL:** <https://discuss.elastic.co/t/source-document-is-not-storing-as-mentioned-in-java-api/6583>\
**Category:** Elasticsearch\
**Created:** [February 3, 2012, 4:06pm UTC](https://discuss.elastic.co/t/source-document-is-not-storing-as-mentioned-in-java-api/6583 "2012-02-03T16:06:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prashanth](https://avatars.discourse-cdn.com/v4/letter/p/439d5e/32.png) [@Prashanth](https://discuss.elastic.co/u/Prashanth)\
**Post date:** [February 3, 2012, 4:06pm UTC](https://discuss.elastic.co/t/source-document-is-not-storing-as-mentioned-in-java-api/6583/1 "2012-02-03T16:06:04Z")

</div>

Hi,

When i set the following source using java api while creating the  
document, it is being stored in a wrong way.  
{  
"extID": "ConstructionProject",  
"catName": [  
{  
"language": "en",  
"text": "ProjectWBSType",  
"original": false  
}  
],  
"typeIcon": "",  
"changedOn": "2012-01-27T18:47:14+0530",  
"busUntis": "4e52b623a9801a7a3ba86c8e Test Company",  
"tags": "",  
"comments": "",  
"responsible": "Prashanth"  
}

When i do the query on the above document, in the search result,  
following source is being displayed.

Used REST URL :[http://localhost:9200/100-en/TypeName/](http://localhost:9200/100-en/TypeName/)  
4e6601afa980073d473d491b

{  
"\_index": "100-en",  
"\_type": "TypeName",  
"\_id": "4e6601afa980073d473d491b",  
"\_version": 2,  
"exists": true,  
"\_source": {  
"changedOn": "2012-01-27T18:47:14+0530",  
"responsible": "prashanth"  
}  
}

Please let me know what is being done in a wrong way.

Thanks,  
Prashanth

---

<div class="post-metadata">

**Author:** ![Prashanth](https://avatars.discourse-cdn.com/v4/letter/p/439d5e/32.png) [@Prashanth](https://discuss.elastic.co/u/Prashanth)\
**Post date:** [February 3, 2012, 4:40pm UTC](https://discuss.elastic.co/t/source-document-is-not-storing-as-mentioned-in-java-api/6583/2 "2012-02-03T16:40:26Z")

</div>

When I create the document using PUT request with the above JSON data,  
everything is working as expected( REST GET API is returning the same  
data that i have used to insert )..Seems issue with java api.i used  
the following piece of code..  
IndexRequestBuilder indexBuilder = esClient.prepareIndex(  
"indexname"," type", documentId);

```
	indexBuilder.setSource("above JSON String").execute();
```

---

<div class="post-metadata">

**Author:** ![louis\_gueye](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/louis_gueye/32/2772_2.png) [@louis\_gueye](https://discuss.elastic.co/u/louis_gueye)\
**Post date:** [February 3, 2012, 4:56pm UTC](https://discuss.elastic.co/t/source-document-is-not-storing-as-mentioned-in-java-api/6583/3 "2012-02-03T16:56:37Z")

</div>

Try this :

String jsonByteArray = "above JSON String".getBytes("UTF-8");  
indexBuilder.setSource(jsonByteArray).execute();

Hope it will work

2012/2/3 Prashanth [prashanth.byrapu@gmail.com](mailto:prashanth.byrapu@gmail.com)

> When I create the document using PUT request with the above JSON data,  
> everything is working as expected( REST GET API is returning the same  
> data that i have used to insert )..Seems issue with java api.i used  
> the following piece of code..  
> IndexRequestBuilder indexBuilder = esClient.prepareIndex(  
> "indexname"," type", documentId);
> 
> ```
> indexBuilder.setSource("above JSON String").execute();
> 
> ```

--  
Cordialement/Regards,

Louis GUEYE  
linkedin [http://fr.linkedin.com/in/louisgueye](http://fr.linkedin.com/in/louisgueye) |  
blog[http://deepintojee.wordpress.com/](http://deepintojee.wordpress.com/)|  
twitter [http://twitter.com/#!/lgueye](http://twitter.com/#%21/lgueye)

---

<div class="post-metadata">

**Author:** ![Prashanth](https://avatars.discourse-cdn.com/v4/letter/p/439d5e/32.png) [@Prashanth](https://discuss.elastic.co/u/Prashanth)\
**Post date:** [February 4, 2012, 12:27am UTC](https://discuss.elastic.co/t/source-document-is-not-storing-as-mentioned-in-java-api/6583/4 "2012-02-04T00:27:31Z")

</div>

I have tired this..no luck ☹

On Feb 3, 9:56 pm, louis gueye [louis.gu...@gmail.com](mailto:louis.gu...@gmail.com) wrote:

> Try this :
> 
> String jsonByteArray = "above JSON String".getBytes("UTF-8");  
> indexBuilder.setSource(jsonByteArray).execute();
> 
> Hope it will work
> 
> 2012/2/3 Prashanth [prashanth.byr...@gmail.com](mailto:prashanth.byr...@gmail.com)
> 
> > When I create the document using PUT request with the above JSON data,  
> > everything is working as expected( REST GET API is returning the same  
> > data that i have used to insert )..Seems issue with java api.i used  
> > the following piece of code..  
> > IndexRequestBuilder indexBuilder = esClient.prepareIndex(  
> > "indexname"," type", documentId);
> 
> > ```
> > indexBuilder.setSource("above JSON String").execute();
> > 
> > ```
> 
> --  
> Cordialement/Regards,
> 
> Louis GUEYE  
> linkedin [http://fr.linkedin.com/in/louisgueye](http://fr.linkedin.com/in/louisgueye) |  
> blog[http://deepintojee.wordpress.com/](http://deepintojee.wordpress.com/)|  
> twitter [http://twitter.com/#!/lgueye](http://twitter.com/#%21/lgueye)

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [February 5, 2012, 4:27pm UTC](https://discuss.elastic.co/t/source-document-is-not-storing-as-mentioned-in-java-api/6583/5 "2012-02-05T16:27:18Z")

</div>

Can you gist your code that index the document?

On Saturday, February 4, 2012 at 2:27 AM, Prashanth wrote:

> I have tired this..no luck ☹
> 
> On Feb 3, 9:56 pm, louis gueye \<[louis.gu...@gmail.com](mailto:louis.gu...@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> 
> > Try this :
> > 
> > String jsonByteArray = "above JSON String".getBytes("UTF-8");  
> > indexBuilder.setSource(jsonByteArray).execute();
> > 
> > Hope it will work
> > 
> > 2012/2/3 Prashanth \<[prashanth.byr...@gmail.com](mailto:prashanth.byr...@gmail.com) ([http://gmail.com](http://gmail.com))\>
> > 
> > > When I create the document using PUT request with the above JSON data,  
> > > everything is working as expected( REST GET API is returning the same  
> > > data that i have used to insert )..Seems issue with java api.i used  
> > > the following piece of code..  
> > > IndexRequestBuilder indexBuilder = esClient.prepareIndex(  
> > > "indexname"," type", documentId);
> > 
> > > ```
> > > indexBuilder.setSource("above JSON String").execute();
> > > 
> > > ```
> > 
> > --  
> > Cordialement/Regards,
> > 
> > Louis GUEYE  
> > linkedin [http://fr.linkedin.com/in/louisgueye](http://fr.linkedin.com/in/louisgueye) |  
> > blog[http://deepintojee.wordpress.com/](http://deepintojee.wordpress.com/)|  
> > twitter [http://twitter.com/#!/lgueye](http://twitter.com/#%21/lgueye)

---

<div class="post-metadata">

**Author:** ![Prashanth](https://avatars.discourse-cdn.com/v4/letter/p/439d5e/32.png) [@Prashanth](https://discuss.elastic.co/u/Prashanth)\
**Post date:** [February 27, 2012, 7:33am UTC](https://discuss.elastic.co/t/source-document-is-not-storing-as-mentioned-in-java-api/6583/6 "2012-02-27T07:33:31Z")

</div>

Hi Shay,

```
  Is there any logging or any other trouble shooting mechanism to

```

find out the exact issue here?.

```
  If I pass the same data in stand alone program , everything is

```

working fine. But, in the integrated environment , issue is coming. I  
have double checked everything from my side and looks like the same  
string value is passed to setSource method using java api. I can see  
the exact string value in the log file also but after creating the  
index, the data is not same as it is shown in the logger.

Below is the code snippet --  
Client esClient = new TransportClient()  
.addTransportAddress(new InetSocketTransportAddress(  
"localhost", 9300));

```
	IndexRequestBuilder indexBuilder = esClient.prepareIndex("index3",

```

"objecttype", "123456");  
// Get Json Data..using gson library..by converting a java bean to  
json.  
logger.info("Json String :: " + jsonData );  
indexBuilder.setSource(jsonData);

Thanks,  
Prashanth

On Feb 5, 10:27 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> Can you gist your code that index the document?
> 
> On Saturday, February 4, 2012 at 2:27 AM, Prashanth wrote:
> 
> > I have tired this..no luck ☹
> 
> > On Feb 3, 9:56 pm, louis gueye \<[louis.gu...@gmail.com](mailto:louis.gu...@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> > 
> > > Try this :
> 
> > > String jsonByteArray = "above JSON String".getBytes("UTF-8");  
> > > indexBuilder.setSource(jsonByteArray).execute();
> 
> > > Hope it will work
> 
> > > 2012/2/3 Prashanth \<[prashanth.byr...@gmail.com](mailto:prashanth.byr...@gmail.com) ([http://gmail.com](http://gmail.com))\>
> 
> > > > When I create the document using PUT request with the above JSON data,  
> > > > everything is working as expected( REST GET API is returning the same  
> > > > data that i have used to insert )..Seems issue with java api.i used  
> > > > the following piece of code..  
> > > > IndexRequestBuilder indexBuilder = esClient.prepareIndex(  
> > > > "indexname"," type", documentId);
> 
> > > > ```
> > > > indexBuilder.setSource("above JSON String").execute();
> > > > 
> > > > ```
> 
> > > --  
> > > Cordialement/Regards,
> 
> > > Louis GUEYE  
> > > linkedin [http://fr.linkedin.com/in/louisgueye](http://fr.linkedin.com/in/louisgueye) |  
> > > blog[http://deepintojee.wordpress.com/](http://deepintojee.wordpress.com/)|  
> > > twitter [http://twitter.com/#!/lgueye](http://twitter.com/#%21/lgueye)

---

<div class="post-metadata">

**Author:** ![Prashanth](https://avatars.discourse-cdn.com/v4/letter/p/439d5e/32.png) [@Prashanth](https://discuss.elastic.co/u/Prashanth)\
**Post date:** [February 27, 2012, 7:46am UTC](https://discuss.elastic.co/t/source-document-is-not-storing-as-mentioned-in-java-api/6583/7 "2012-02-27T07:46:00Z")

</div>

sorry, issue is found finally and it is in my coding... :-).. thanks  
for your help

On Feb 27, 1:33 am, Prashanth [prashanth.byr...@gmail.com](mailto:prashanth.byr...@gmail.com) wrote:

> Hi Shay,
> 
> ```
> Is there any logging or any other trouble shooting mechanism to
> 
> ```
> 
> find out the exact issue here?.
> 
> ```
> If I pass the same data in stand alone program , everything is
> 
> ```
> 
> working fine. But, in the integrated environment , issue is coming. I  
> have double checked everything from my side and looks like the same  
> string value is passed to setSource method using java api. I can see  
> the exact string value in the log file also but after creating the  
> index, the data is not same as it is shown in the logger.
> 
> Below is the code snippet --  
> Client esClient = new TransportClient()  
> .addTransportAddress(new InetSocketTransportAddress(  
> "localhost", 9300));
> 
> ```
> IndexRequestBuilder indexBuilder = esClient.prepareIndex("index3",
> 
> ```
> 
> "objecttype", "123456");  
> // Get Json Data..using gson library..by converting a java bean to  
> json.  
> logger.info("Json String :: " + jsonData );  
> indexBuilder.setSource(jsonData);
> 
> Thanks,  
> Prashanth
> 
> On Feb 5, 10:27 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > Can you gist your code that index the document?
> 
> > On Saturday, February 4, 2012 at 2:27 AM, Prashanth wrote:
> > 
> > > I have tired this..no luck ☹
> 
> > > On Feb 3, 9:56 pm, louis gueye \<[louis.gu...@gmail.com](mailto:louis.gu...@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> > > 
> > > > Try this :
> 
> > > > String jsonByteArray = "above JSON String".getBytes("UTF-8");  
> > > > indexBuilder.setSource(jsonByteArray).execute();
> 
> > > > Hope it will work
> 
> > > > 2012/2/3 Prashanth \<[prashanth.byr...@gmail.com](mailto:prashanth.byr...@gmail.com) ([http://gmail.com](http://gmail.com))\>
> 
> > > > > When I create the document using PUT request with the above JSON data,  
> > > > > everything is working as expected( REST GET API is returning the same  
> > > > > data that i have used to insert )..Seems issue with java api.i used  
> > > > > the following piece of code..  
> > > > > IndexRequestBuilder indexBuilder = esClient.prepareIndex(  
> > > > > "indexname"," type", documentId);
> 
> > > > > ```
> > > > > indexBuilder.setSource("above JSON String").execute();
> > > > > 
> > > > > ```
> 
> > > > --  
> > > > Cordialement/Regards,
> 
> > > > Louis GUEYE  
> > > > linkedin [http://fr.linkedin.com/in/louisgueye](http://fr.linkedin.com/in/louisgueye) |  
> > > > blog[http://deepintojee.wordpress.com/](http://deepintojee.wordpress.com/)|  
> > > > twitter [http://twitter.com/#!/lgueye](http://twitter.com/#%21/lgueye)

---

<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:38am UTC](https://discuss.elastic.co/t/source-document-is-not-storing-as-mentioned-in-java-api/6583/8 "2017-07-06T03:38:07Z")

</div>


