Is object storage mandatory for new Java API?

From this link

I can see that indexing is using an object storage strategy

        // Ingest some data
        AppData appData = new AppData();

        String docId = client.index(b -> b
            .id("my/Id") // test with url-unsafe string
            .refresh(Refresh.True) // Make it visible for search

The process seems to be the following:

  1. Create a class with properties only
  2. Fill up an instance of this class
  3. Send it to indexer which will identify your columns names from the getters and setters

My concern is that this object storage strategy looks very hard coded
You seem to have to declare and compile a class for every index structure.

In HLRC you had to fill up a XContentBuilder and send it. It relied on the mapping to recognize the field names dynamically. No programming adherence. One program fitted all.

Please tell me that this agnostic mode still exists in the new Java API :sweat_smile: ?

"He who can do more can do less" :wink:

Raw JSON data is just another kind of object, so you can use Jackson's ObjectNode or the built-in mapper independent JsonData class. Anything that the JSON mapper is able to handle.

Thanks for the feedback, we'll expand the docs on this topic to avoid this kind of confusion.

Thank you Sylvain for reassuring us all :grin: !

1 Like

Digging further, I could not find a convenient way to build a JsonData class

All I could find was :melting_face:
Build a good ole and call this method:

    public JsonData jsonObjectToJsonData(JSONObject jsonObject) {

        String json = jsonObject.toString();
        JsonpMapper mapper = new JsonbJsonpMapper();
        JsonParser parser = mapper.jsonProvider().createParser(new StringReader(json));
        JsonData jsonData = JsonData.from(parser, mapper);

        return jsonData;

This is not very efficient: The JSONObject is dumped into a String that is reparsed.

Could you provide a snippet to build a JsonData Object directly.
Something like

jo = new JsonData();
jo.put("field2",["value1", "value2"]);

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.