# Build IndexRequest with elastic in 8.1.0

**URL:** <https://discuss.elastic.co/t/build-indexrequest-with-elastic-in-8-1-0/300146>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [March 21, 2022, 3:32am UTC](https://discuss.elastic.co/t/build-indexrequest-with-elastic-in-8-1-0/300146 "2022-03-21T03:32:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raushan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raushan/32/102180_2.png) [@Raushan](https://discuss.elastic.co/u/Raushan)\
**Post date:** [March 21, 2022, 3:32am UTC](https://discuss.elastic.co/t/build-indexrequest-with-elastic-in-8-1-0/300146/1 "2022-03-21T03:32:06Z")

</div>

Hi, I am migrating from HLRC to Elasticsearch Java API Client. I need to transform below code

```auto
private IndexRequest buildIndex(String indexName, CacheObject cacheObject) {
        IndexRequest indexRequest = new IndexRequest(indexName);
        indexRequest.source(new String(cacheObject.getValueAsByteArr()), XContentType.JSON);
        indexRequest.id(buildIdFromCacheObject(cacheObject.getKey()));
        return indexRequest;
}

```

I tried

```auto
 private IndexRequest buildIndex(String indexName, CacheObject cacheObject) {
        IndexRequest indexRequest = new IndexRequest.Builder<CVDocument>()
                .index(indexName)
                .id(buildIdFromCacheObject(cacheObject.getKey()))
                .build();
        // **HOW TO SET SOURCE**
        //indexRequest.source(new String(cacheObject.getValueAsByteArr()), XContentType.JSON);
        return indexRequest;
    }

```

where my CVDocument is

```auto
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

@Data
public class CVDocument {
    @JsonProperty("_id")
    private Integer id;

    @JsonProperty("cvFR")
    private Integer cvFR;

    @JsonProperty("cvEN")
    private Integer cvEN;
}

```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [March 21, 2022, 8:16am UTC](https://discuss.elastic.co/t/build-indexrequest-with-elastic-in-8-1-0/300146/2 "2022-03-21T08:16:18Z")

</div>

you can set the source document using `document()` as a POJO and a JSON library is doing the serialization.

Would that work for you, or do you only have the byte array representation?

---

<div class="post-metadata">

**Author:** ![Raushan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raushan/32/102180_2.png) [@Raushan](https://discuss.elastic.co/u/Raushan)\
**Post date:** [March 23, 2022, 5:50pm UTC](https://discuss.elastic.co/t/build-indexrequest-with-elastic-in-8-1-0/300146/3 "2022-03-23T17:50:30Z")

</div>

we have complex json in byte array representation

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [March 24, 2022, 8:09am UTC](https://discuss.elastic.co/t/build-indexrequest-with-elastic-in-8-1-0/300146/4 "2022-03-24T08:09:01Z")

</div>

With the next release this will be possible. See [Raw json support by swallez · Pull Request #200 · elastic/elasticsearch-java · GitHub](https://github.com/elastic/elasticsearch-java/pull/200)

---

<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 21, 2022, 8:09am UTC](https://discuss.elastic.co/t/build-indexrequest-with-elastic-in-8-1-0/300146/5 "2022-04-21T08:09:56Z")

</div>

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