# Indexing Objects with Java

**URL:** <https://discuss.elastic.co/t/indexing-objects-with-java/6075>\
**Category:** Elasticsearch\
**Created:** [December 6, 2011, 1:45pm UTC](https://discuss.elastic.co/t/indexing-objects-with-java/6075 "2011-12-06T13:45:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![marrese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marrese/32/3037_2.png) [@marrese](https://discuss.elastic.co/u/marrese)\
**Post date:** [December 6, 2011, 1:45pm UTC](https://discuss.elastic.co/t/indexing-objects-with-java/6075/1 "2011-12-06T13:45:38Z")

</div>

Hi,

I'm testing Elasticsearch as replacement to our current MongoDB  
implementation for storing and searching information.  
The application I'm working on has a Django frontend that query the  
information, and an engine built with Java. I have almost no experience  
working with Java, so I'm having some trouble to figure out how to store  
objects that have other objects as attributes.

As you can see in here (1), I'm creating an user object with the  
information I need to store, and then I set this user as a content  
attribute.  
I know I'm doing something wrong because the document gets stored without  
the user information. In the log files, the user entry is sent as string  
('user': {'type': 'string'}) .

I thought to use a Map to store those fields I need from the user object,  
but I don't know if that is the Java way or even a nice way to doit.

Could someone throw me a line here?

Thanks,  
Martin

Links:  
1- [https://gist.github.com/1438221](https://gist.github.com/1438221)

--  
Martín

[http://www.kyheo.com.ar](http://www.kyheo.com.ar)  
GTalk: [marrese@gmail.com](mailto:marrese@gmail.com)

---

<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:** [December 6, 2011, 8:37pm UTC](https://discuss.elastic.co/t/indexing-objects-with-java/6075/2 "2011-12-06T20:37:14Z")

</div>

When you build the json, you need to have another "startObject" and  
"endObject" to wrap the json you construct (startObject == {, endObject ==  
}).

On Tue, Dec 6, 2011 at 3:45 PM, [marrese@gmail.com](mailto:marrese@gmail.com) [marrese@gmail.com](mailto:marrese@gmail.com) wrote:

> Hi,
> 
> I'm testing Elasticsearch as replacement to our current MongoDB  
> implementation for storing and searching information.  
> The application I'm working on has a Django frontend that query the  
> information, and an engine built with Java. I have almost no experience  
> working with Java, so I'm having some trouble to figure out how to store  
> objects that have other objects as attributes.
> 
> As you can see in here (1), I'm creating an user object with the  
> information I need to store, and then I set this user as a content  
> attribute.  
> I know I'm doing something wrong because the document gets stored without  
> the user information. In the log files, the user entry is sent as string  
> ('user': {'type': 'string'}) .
> 
> I thought to use a Map to store those fields I need from the user object,  
> but I don't know if that is the Java way or even a nice way to doit.
> 
> Could someone throw me a line here?
> 
> Thanks,  
> Martin
> 
> Links:  
> 1- [https://gist.github.com/1438221](https://gist.github.com/1438221)
> 
> --  
> Martín
> 
> [http://www.kyheo.com.ar](http://www.kyheo.com.ar)  
> GTalk: [marrese@gmail.com](mailto:marrese@gmail.com)

---

<div class="post-metadata">

**Author:** ![marrese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marrese/32/3037_2.png) [@marrese](https://discuss.elastic.co/u/marrese)\
**Post date:** [December 7, 2011, 3:43pm UTC](https://discuss.elastic.co/t/indexing-objects-with-java/6075/3 "2011-12-07T15:43:01Z")

</div>

Shay,

Thanks for the response, but sadly I didn't got it working.

I don't understand where should I put the extra startObject and endObjects  
calls. The user object is already created with startObject and endObject.  
If I call them when adding the user object to the content one I got an  
exception.

Could you please be a little more specific, and perhaps with the two or  
three lines that will do what you said ? ... I'm really new with Java and  
I'm still struggling with language issues :S

Thanks.  
Martin

On Tue, Dec 6, 2011 at 17:37, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> When you build the json, you need to have another "startObject" and  
> "endObject" to wrap the json you construct (startObject == {, endObject ==  
> }).
> 
> On Tue, Dec 6, 2011 at 3:45 PM, [marrese@gmail.com](mailto:marrese@gmail.com) [marrese@gmail.com](mailto:marrese@gmail.com)wrote:
> 
> > Hi,
> > 
> > I'm testing Elasticsearch as replacement to our current MongoDB  
> > implementation for storing and searching information.  
> > The application I'm working on has a Django frontend that query the  
> > information, and an engine built with Java. I have almost no experience  
> > working with Java, so I'm having some trouble to figure out how to store  
> > objects that have other objects as attributes.
> > 
> > As you can see in here (1), I'm creating an user object with the  
> > information I need to store, and then I set this user as a content  
> > attribute.  
> > I know I'm doing something wrong because the document gets stored without  
> > the user information. In the log files, the user entry is sent as string  
> > ('user': {'type': 'string'}) .
> > 
> > I thought to use a Map to store those fields I need from the user object,  
> > but I don't know if that is the Java way or even a nice way to doit.
> > 
> > Could someone throw me a line here?
> > 
> > Thanks,  
> > Martin
> > 
> > Links:  
> > 1- [https://gist.github.com/1438221](https://gist.github.com/1438221)
> > 
> > --  
> > Martín
> > 
> > [http://www.kyheo.com.ar](http://www.kyheo.com.ar)  
> > GTalk: [marrese@gmail.com](mailto:marrese@gmail.com)

--  
Martín

[http://www.kyheo.com.ar](http://www.kyheo.com.ar)  
GTalk: [marrese@gmail.com](mailto:marrese@gmail.com)

---

<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:** [December 7, 2011, 3:54pm UTC](https://discuss.elastic.co/t/indexing-objects-with-java/6075/4 "2011-12-07T15:54:33Z")

</div>

Sorry, I got confused by your code a bit. I commented with something that  
should work (the user aspect). I also added setId just so you can more  
easily fetch it by id (if you test it), nad actionGet() at the end of the  
index to wait for the index operation to finish (execute is async).

On Wed, Dec 7, 2011 at 5:43 PM, [marrese@gmail.com](mailto:marrese@gmail.com) [marrese@gmail.com](mailto:marrese@gmail.com) wrote:

> Shay,
> 
> Thanks for the response, but sadly I didn't got it working.
> 
> I don't understand where should I put the extra startObject and endObjects  
> calls. The user object is already created with startObject and endObject.  
> If I call them when adding the user object to the content one I got an  
> exception.
> 
> Could you please be a little more specific, and perhaps with the two or  
> three lines that will do what you said ? ... I'm really new with Java and  
> I'm still struggling with language issues :S
> 
> Thanks.  
> Martin
> 
> On Tue, Dec 6, 2011 at 17:37, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> 
> > When you build the json, you need to have another "startObject" and  
> > "endObject" to wrap the json you construct (startObject == {, endObject ==  
> > }).
> > 
> > On Tue, Dec 6, 2011 at 3:45 PM, [marrese@gmail.com](mailto:marrese@gmail.com) [marrese@gmail.com](mailto:marrese@gmail.com)wrote:
> > 
> > > Hi,
> > > 
> > > I'm testing Elasticsearch as replacement to our current MongoDB  
> > > implementation for storing and searching information.  
> > > The application I'm working on has a Django frontend that query the  
> > > information, and an engine built with Java. I have almost no experience  
> > > working with Java, so I'm having some trouble to figure out how to store  
> > > objects that have other objects as attributes.
> > > 
> > > As you can see in here (1), I'm creating an user object with the  
> > > information I need to store, and then I set this user as a content  
> > > attribute.  
> > > I know I'm doing something wrong because the document gets stored  
> > > without the user information. In the log files, the user entry is sent as  
> > > string ('user': {'type': 'string'}) .
> > > 
> > > I thought to use a Map to store those fields I need from the user  
> > > object, but I don't know if that is the Java way or even a nice way to doit.
> > > 
> > > Could someone throw me a line here?
> > > 
> > > Thanks,  
> > > Martin
> > > 
> > > Links:  
> > > 1- [https://gist.github.com/1438221](https://gist.github.com/1438221)
> > > 
> > > --  
> > > Martín
> > > 
> > > [http://www.kyheo.com.ar](http://www.kyheo.com.ar)  
> > > GTalk: [marrese@gmail.com](mailto:marrese@gmail.com)
> 
> --  
> Martín
> 
> [http://www.kyheo.com.ar](http://www.kyheo.com.ar)  
> GTalk: [marrese@gmail.com](mailto:marrese@gmail.com)

---

<div class="post-metadata">

**Author:** ![marrese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marrese/32/3037_2.png) [@marrese](https://discuss.elastic.co/u/marrese)\
**Post date:** [December 7, 2011, 3:57pm UTC](https://discuss.elastic.co/t/indexing-objects-with-java/6075/5 "2011-12-07T15:57:38Z")

</div>

Shay,

Thanks, I'm looking it right know and will try it in a bit ...

Martin

On Wed, Dec 7, 2011 at 12:54, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> Sorry, I got confused by your code a bit. I commented with something that  
> should work (the user aspect). I also added setId just so you can more  
> easily fetch it by id (if you test it), nad actionGet() at the end of the  
> index to wait for the index operation to finish (execute is async).
> 
> On Wed, Dec 7, 2011 at 5:43 PM, [marrese@gmail.com](mailto:marrese@gmail.com) [marrese@gmail.com](mailto:marrese@gmail.com)wrote:
> 
> > Shay,
> > 
> > Thanks for the response, but sadly I didn't got it working.
> > 
> > I don't understand where should I put the extra startObject and  
> > endObjects calls. The user object is already created with startObject and  
> > endObject. If I call them when adding the user object to the content one I  
> > got an exception.
> > 
> > Could you please be a little more specific, and perhaps with the two or  
> > three lines that will do what you said ? ... I'm really new with Java and  
> > I'm still struggling with language issues :S
> > 
> > Thanks.  
> > Martin
> > 
> > On Tue, Dec 6, 2011 at 17:37, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> > 
> > > When you build the json, you need to have another "startObject" and  
> > > "endObject" to wrap the json you construct (startObject == {, endObject ==  
> > > }).
> > > 
> > > On Tue, Dec 6, 2011 at 3:45 PM, [marrese@gmail.com](mailto:marrese@gmail.com) [marrese@gmail.com](mailto:marrese@gmail.com)wrote:
> > > 
> > > > Hi,
> > > > 
> > > > I'm testing Elasticsearch as replacement to our current MongoDB  
> > > > implementation for storing and searching information.  
> > > > The application I'm working on has a Django frontend that query the  
> > > > information, and an engine built with Java. I have almost no experience  
> > > > working with Java, so I'm having some trouble to figure out how to store  
> > > > objects that have other objects as attributes.
> > > > 
> > > > As you can see in here (1), I'm creating an user object with the  
> > > > information I need to store, and then I set this user as a content  
> > > > attribute.  
> > > > I know I'm doing something wrong because the document gets stored  
> > > > without the user information. In the log files, the user entry is sent as  
> > > > string ('user': {'type': 'string'}) .
> > > > 
> > > > I thought to use a Map to store those fields I need from the user  
> > > > object, but I don't know if that is the Java way or even a nice way to doit.
> > > > 
> > > > Could someone throw me a line here?
> > > > 
> > > > Thanks,  
> > > > Martin
> > > > 
> > > > Links:  
> > > > 1- [https://gist.github.com/1438221](https://gist.github.com/1438221)
> > > > 
> > > > --  
> > > > Martín
> > > > 
> > > > [http://www.kyheo.com.ar](http://www.kyheo.com.ar)  
> > > > GTalk: [marrese@gmail.com](mailto:marrese@gmail.com)
> > 
> > --  
> > Martín
> > 
> > [http://www.kyheo.com.ar](http://www.kyheo.com.ar)  
> > GTalk: [marrese@gmail.com](mailto:marrese@gmail.com)

--  
Martín

[http://www.kyheo.com.ar](http://www.kyheo.com.ar)  
GTalk: [marrese@gmail.com](mailto:marrese@gmail.com)

---

<div class="post-metadata">

**Author:** ![Michael\_Sick](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@Michael\_Sick](https://discuss.elastic.co/u/Michael_Sick)\
**Post date:** [December 7, 2011, 4:05pm UTC](https://discuss.elastic.co/t/indexing-objects-with-java/6075/6 "2011-12-07T16:05:40Z")

</div>

Martin,

Hope you bit the bullet sometime for Java but you can probably avoid using  
it - at least to start/evaluate. I believe the ElastiSearc Head plugin only  
uses JavaScript to interact with ES. You might be able to do JS call  
replacements under Django.This might not be your long term solution but  
could let you see what ES can do. I also believe there are some JS clients  
for ES out there - though not sure if any are current/blessed.  
--Mike

On Wed, Dec 7, 2011 at 10:43 AM, [marrese@gmail.com](mailto:marrese@gmail.com) [marrese@gmail.com](mailto:marrese@gmail.com)wrote:

> Shay,
> 
> Thanks for the response, but sadly I didn't got it working.
> 
> I don't understand where should I put the extra startObject and endObjects  
> calls. The user object is already created with startObject and endObject.  
> If I call them when adding the user object to the content one I got an  
> exception.
> 
> Could you please be a little more specific, and perhaps with the two or  
> three lines that will do what you said ? ... I'm really new with Java and  
> I'm still struggling with language issues :S
> 
> Thanks.  
> Martin
> 
> On Tue, Dec 6, 2011 at 17:37, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> 
> > When you build the json, you need to have another "startObject" and  
> > "endObject" to wrap the json you construct (startObject == {, endObject ==  
> > }).
> > 
> > On Tue, Dec 6, 2011 at 3:45 PM, [marrese@gmail.com](mailto:marrese@gmail.com) [marrese@gmail.com](mailto:marrese@gmail.com)wrote:
> > 
> > > Hi,
> > > 
> > > I'm testing Elasticsearch as replacement to our current MongoDB  
> > > implementation for storing and searching information.  
> > > The application I'm working on has a Django frontend that query the  
> > > information, and an engine built with Java. I have almost no experience  
> > > working with Java, so I'm having some trouble to figure out how to store  
> > > objects that have other objects as attributes.
> > > 
> > > As you can see in here (1), I'm creating an user object with the  
> > > information I need to store, and then I set this user as a content  
> > > attribute.  
> > > I know I'm doing something wrong because the document gets stored  
> > > without the user information. In the log files, the user entry is sent as  
> > > string ('user': {'type': 'string'}) .
> > > 
> > > I thought to use a Map to store those fields I need from the user  
> > > object, but I don't know if that is the Java way or even a nice way to doit.
> > > 
> > > Could someone throw me a line here?
> > > 
> > > Thanks,  
> > > Martin
> > > 
> > > Links:  
> > > 1- [https://gist.github.com/1438221](https://gist.github.com/1438221)
> > > 
> > > --  
> > > Martín
> > > 
> > > [http://www.kyheo.com.ar](http://www.kyheo.com.ar)  
> > > GTalk: [marrese@gmail.com](mailto:marrese@gmail.com)
> 
> --  
> Martín
> 
> [http://www.kyheo.com.ar](http://www.kyheo.com.ar)  
> GTalk: [marrese@gmail.com](mailto:marrese@gmail.com)

---

<div class="post-metadata">

**Author:** ![marrese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marrese/32/3037_2.png) [@marrese](https://discuss.elastic.co/u/marrese)\
**Post date:** [December 7, 2011, 4:10pm UTC](https://discuss.elastic.co/t/indexing-objects-with-java/6075/7 "2011-12-07T16:10:38Z")

</div>

Mike,

I got it working with what Shay said, so I can test ES using the same app  
we have right know, just with another storage.

Thank you both,  
Martin

On Wed, Dec 7, 2011 at 13:05, Michael Sick  
[michael.sick@serenesoftware.com](mailto:michael.sick@serenesoftware.com)wrote:

> Martin,
> 
> Hope you bit the bullet sometime for Java but you can probably avoid using  
> it - at least to start/evaluate. I believe the ElastiSearc Head plugin only  
> uses JavaScript to interact with ES. You might be able to do JS call  
> replacements under Django.This might not be your long term solution but  
> could let you see what ES can do. I also believe there are some JS clients  
> for ES out there - though not sure if any are current/blessed.  
> --Mike
> 
> On Wed, Dec 7, 2011 at 10:43 AM, [marrese@gmail.com](mailto:marrese@gmail.com) [marrese@gmail.com](mailto:marrese@gmail.com)wrote:
> 
> > Shay,
> > 
> > Thanks for the response, but sadly I didn't got it working.
> > 
> > I don't understand where should I put the extra startObject and  
> > endObjects calls. The user object is already created with startObject and  
> > endObject. If I call them when adding the user object to the content one I  
> > got an exception.
> > 
> > Could you please be a little more specific, and perhaps with the two or  
> > three lines that will do what you said ? ... I'm really new with Java and  
> > I'm still struggling with language issues :S
> > 
> > Thanks.  
> > Martin
> > 
> > On Tue, Dec 6, 2011 at 17:37, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> > 
> > > When you build the json, you need to have another "startObject" and  
> > > "endObject" to wrap the json you construct (startObject == {, endObject ==  
> > > }).
> > > 
> > > On Tue, Dec 6, 2011 at 3:45 PM, [marrese@gmail.com](mailto:marrese@gmail.com) [marrese@gmail.com](mailto:marrese@gmail.com)wrote:
> > > 
> > > > Hi,
> > > > 
> > > > I'm testing Elasticsearch as replacement to our current MongoDB  
> > > > implementation for storing and searching information.  
> > > > The application I'm working on has a Django frontend that query the  
> > > > information, and an engine built with Java. I have almost no experience  
> > > > working with Java, so I'm having some trouble to figure out how to store  
> > > > objects that have other objects as attributes.
> > > > 
> > > > As you can see in here (1), I'm creating an user object with the  
> > > > information I need to store, and then I set this user as a content  
> > > > attribute.  
> > > > I know I'm doing something wrong because the document gets stored  
> > > > without the user information. In the log files, the user entry is sent as  
> > > > string ('user': {'type': 'string'}) .
> > > > 
> > > > I thought to use a Map to store those fields I need from the user  
> > > > object, but I don't know if that is the Java way or even a nice way to doit.
> > > > 
> > > > Could someone throw me a line here?
> > > > 
> > > > Thanks,  
> > > > Martin
> > > > 
> > > > Links:  
> > > > 1- [https://gist.github.com/1438221](https://gist.github.com/1438221)
> > > > 
> > > > --  
> > > > Martín
> > > > 
> > > > [http://www.kyheo.com.ar](http://www.kyheo.com.ar)  
> > > > GTalk: [marrese@gmail.com](mailto:marrese@gmail.com)
> > 
> > --  
> > Martín
> > 
> > [http://www.kyheo.com.ar](http://www.kyheo.com.ar)  
> > GTalk: [marrese@gmail.com](mailto:marrese@gmail.com)

--  
Martín

[http://www.kyheo.com.ar](http://www.kyheo.com.ar)  
GTalk: [marrese@gmail.com](mailto:marrese@gmail.com)

---

<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:46am UTC](https://discuss.elastic.co/t/indexing-objects-with-java/6075/8 "2017-07-06T03:46:10Z")

</div>


