# Is object storage mandatory for new Java API?

**URL:** <https://discuss.elastic.co/t/is-object-storage-mandatory-for-new-java-api/300481>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [March 23, 2022, 3:41pm UTC](https://discuss.elastic.co/t/is-object-storage-mandatory-for-new-java-api/300481 "2022-03-23T15:41:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivanqwam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ivanqwam/32/28102_2.png) [@ivanqwam](https://discuss.elastic.co/u/ivanqwam)\
**Post date:** [March 23, 2022, 3:41pm UTC](https://discuss.elastic.co/t/is-object-storage-mandatory-for-new-java-api/300481/1 "2022-03-23T15:41:13Z")

</div>

From this link

[https://github.com/elastic/elasticsearch-java/blob/main/java-client/src/test/java/co/elastic/clients/elasticsearch/end\_to\_end/RequestTest.java](https://github.com/elastic/elasticsearch-java/blob/main/java-client/src/test/java/co/elastic/clients/elasticsearch/end_to_end/RequestTest.java)

I can see that indexing is using an **object storage strategy**

```auto
        // Ingest some data
        AppData appData = new AppData();
        appData.setIntValue(1337);
        appData.setMsg("foo");

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

```

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 😅 ?

---

<div class="post-metadata">

**Author:** ![swallez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/swallez/32/11972_2.png) [@swallez](https://discuss.elastic.co/u/swallez)\
**Post date:** [March 23, 2022, 5:36pm UTC](https://discuss.elastic.co/t/is-object-storage-mandatory-for-new-java-api/300481/2 "2022-03-23T17:36:05Z")

</div>

"He who can do more can do less" 😉

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.

---

<div class="post-metadata">

**Author:** ![ivanqwam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ivanqwam/32/28102_2.png) [@ivanqwam](https://discuss.elastic.co/u/ivanqwam)\
**Post date:** [March 24, 2022, 8:17am UTC](https://discuss.elastic.co/t/is-object-storage-mandatory-for-new-java-api/300481/3 "2022-03-24T08:17:49Z")

</div>

Thank you Sylvain for reassuring us all 😁 !

---

<div class="post-metadata">

**Author:** ![ivanqwam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ivanqwam/32/28102_2.png) [@ivanqwam](https://discuss.elastic.co/u/ivanqwam)\
**Post date:** [April 1, 2022, 7:11am UTC](https://discuss.elastic.co/t/is-object-storage-mandatory-for-new-java-api/300481/4 "2022-04-01T07:11:25Z")

</div>

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

All I could find was 🫠  
Build a good ole **json.org.JSONObject** and call this method:

```auto
    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

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

```

---

<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:** [April 29, 2022, 7:11am UTC](https://discuss.elastic.co/t/is-object-storage-mandatory-for-new-java-api/300481/5 "2022-04-29T07:11:56Z")

</div>

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