Example of mapping a list of complex objects via Java API


(Shane Witbeck) #1

I've been trying to figure out how to add a list of complex objects via the
Java API as illustrated in the guide here:

http://www.elasticsearch.org/guide/reference/mapping/array-type.html

  1. Is there an example of how to do this?
  2. I'd also be interested an example of how to populate the index via
    Java API.

I'm using version 0.18.7.

Thanks.


(Shay Banon) #2

The index API (http://www.elasticsearch.org/guide/reference/java-api/index_.html) can accept any form of json data (byte array, a string). So, you can create your own json with your favorite json lib, and feed it to the index operation (using the several setSource methods).

There is a built in embedded API to generate json (or smile format, which is a binary json format created by the jackson lib). Thats the one used in the example in the link above. It as different startArray methods.

On Friday, February 10, 2012 at 5:33 PM, Shane Witbeck wrote:

I've been trying to figure out how to add a list of complex objects via the Java API as illustrated in the guide here:

http://www.elasticsearch.org/guide/reference/mapping/array-type.html

Is there an example of how to do this?
I'd also be interested an example of how to populate the index via Java API.
I'm using version 0.18.7.

Thanks.


(Shane Witbeck) #3

You didn't really answer my questions. I was looking for a specific example
using the Java API.

I resorted to externalizing the mapping to a file similar to how it's done
in ES tests.

Thanks anyway.


(system) #4