Quantcast

Indexing Json using Java API

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Indexing Json using Java API

Mohit Anchlia
I am unable to find example of how to index Json String using Java API. Could someone help me with that?
 
I am converting xml to json. I see how to do it in REST api but not sure how this can be done in Java API
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Indexing Json using Java API

Shairon Toledo
You can index the json as string just setting the source, looks like this 

Client client = new TransportClient().addTransportAddress(new InetSocketTransportAddress("localhost", 9300));
String source = yourJson.toString();

IndexResponse idxResp = client.prepareIndex().setIndex("documents").setType("document").setId("1")
            .setSource(source).setRefresh(true).execute().actionGet();


On Tue, May 15, 2012 at 8:20 PM, Mohit Anchlia <[hidden email]> wrote:
I am unable to find example of how to index Json String using Java API. Could someone help me with that?
 
I am converting xml to json. I see how to do it in REST api but not sure how this can be done in Java API



--











Shairon Toledo
http://hashcode.me
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Indexing Json using Java API

Mohit Anchlia
Thanks, that helps. Can that "setType" be anything? I am assuming it's another level of hierarchy.
 
 
On Wed, May 16, 2012 at 11:17 AM, Shairon Toledo <[hidden email]> wrote:
You can index the json as string just setting the source, looks like this 

Client client = new TransportClient().addTransportAddress(new InetSocketTransportAddress("localhost", 9300));
String source = yourJson.toString();

IndexResponse idxResp = client.prepareIndex().setIndex("documents").setType("document").setId("1")
            .setSource(source).setRefresh(true).execute().actionGet();


On Tue, May 15, 2012 at 8:20 PM, Mohit Anchlia <[hidden email]> wrote:
I am unable to find example of how to index Json String using Java API. Could someone help me with that?
 
I am converting xml to json. I see how to do it in REST api but not sure how this can be done in Java API



--











Shairon Toledo
http://hashcode.me

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Indexing Json using Java API

Shairon Toledo
Yeap it is, you can understand that as, an index has many types.

On Wed, May 16, 2012 at 3:20 PM, Mohit Anchlia <[hidden email]> wrote:
Thanks, that helps. Can that "setType" be anything? I am assuming it's another level of hierarchy.
 
 
On Wed, May 16, 2012 at 11:17 AM, Shairon Toledo <[hidden email]> wrote:
You can index the json as string just setting the source, looks like this 

Client client = new TransportClient().addTransportAddress(new InetSocketTransportAddress("localhost", 9300));
String source = yourJson.toString();

IndexResponse idxResp = client.prepareIndex().setIndex("documents").setType("document").setId("1")
            .setSource(source).setRefresh(true).execute().actionGet();


On Tue, May 15, 2012 at 8:20 PM, Mohit Anchlia <[hidden email]> wrote:
I am unable to find example of how to index Json String using Java API. Could someone help me with that?
 
I am converting xml to json. I see how to do it in REST api but not sure how this can be done in Java API



--











Shairon Toledo
http://hashcode.me




--











Shairon Toledo
http://hashcode.me
Loading...