# Ignore fields when indexing using JsonData.of

**URL:** https://discuss.elastic.co/t/ignore-fields-when-indexing-using-jsondata-of/356084
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [March 25, 2024, 9:11am UTC](https://discuss.elastic.co/t/ignore-fields-when-indexing-using-jsondata-of/356084 "2024-03-25T09:11:46Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![ndtreviv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ndtreviv/32/22494_2.png) [@ndtreviv](https://discuss.elastic.co/u/ndtreviv)
#### Post date: [March 25, 2024, 9:11am UTC](https://discuss.elastic.co/t/ignore-fields-when-indexing-using-jsondata-of/356084/1 "2024-03-25T09:11:46Z")

</div>

I'm using the Java SDK to update a document, like so:

```auto
UpdateResponse<Void> response = elasticsearchService.getClient().update(u -> u.index(INDEX)
    .id(id)
    .doc(JsonData.of(myObject)).refresh(Refresh.True), Void.class);

```

In this case myObject has a `@Transient` property on it: `id`, which I populate with `_id` when I load it from elasticsearch.

Unfortunately, when I update like this, the `@Transient` `id` field gets serialised and written into elasticsearch.

How can I prevent that?

---

<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 25, 2024, 10:12am UTC](https://discuss.elastic.co/t/ignore-fields-when-indexing-using-jsondata-of/356084/2 "2024-03-25T10:12:56Z")

</div>

`@Transient` is a JPA annotation that has no impact on JSON serialization. You should probably add `@JsonIgnore` on that property.

See [https://www.baeldung.com/java-jsonignore-vs-transient](https://www.baeldung.com/java-jsonignore-vs-transient)

---

<div class="post-metadata">

### Author: ![ndtreviv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ndtreviv/32/22494_2.png) [@ndtreviv](https://discuss.elastic.co/u/ndtreviv)
#### Post date: [March 25, 2024, 11:14am UTC](https://discuss.elastic.co/t/ignore-fields-when-indexing-using-jsondata-of/356084/3 "2024-03-25T11:14:55Z")

</div>

Thanks, but that's not going to work in this situation. I actually want the id property to be serialised for my user interface.

Literally the only time I don't want it serialised is when it's being written into elasticsearch.

Are there other options? Perhaps something using a Jackson Mixin?

---

<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 25, 2024, 11:35am UTC](https://discuss.elastic.co/t/ignore-fields-when-indexing-using-jsondata-of/356084/4 "2024-03-25T11:35:03Z")

</div>

You should look at Jackson's views and configure a view on the `ObjectMapper` used to create the `JacksonJsonpMapper` in your Elasticsearch client.

See [https://www.baeldung.com/jackson-json-view-annotation](https://www.baeldung.com/jackson-json-view-annotation)

---

<div class="post-metadata">

### Author: ![ndtreviv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ndtreviv/32/22494_2.png) [@ndtreviv](https://discuss.elastic.co/u/ndtreviv)
#### Post date: [March 25, 2024, 11:47am UTC](https://discuss.elastic.co/t/ignore-fields-when-indexing-using-jsondata-of/356084/5 "2024-03-25T11:47:33Z")

</div>

This looks good - do you have an example for how one might configure the ObjectMapper using the Java SDK?

```java
        this.restClient = RestClient.builder(new HttpHost(elasticsearchHost, elasticsearchPort, elasticsearchScheme))
                .setHttpClientConfigCallback(createHttpClientConfigCallback(elasticsearchUsername, elasticsearchPassword, Boolean.TRUE.equals(allowSelfSignedCert)))
                .setRequestConfigCallback(createRequestConfigCallback())
                .build();

        this.client = new ElasticsearchClient(new RestClientTransport(restClient, new JacksonJsonpMapper()));

```

Assuming where I'm using that `new JacksonJsonpMapper()`...?

---

<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 25, 2024, 12:41pm UTC](https://discuss.elastic.co/t/ignore-fields-when-indexing-using-jsondata-of/356084/6 "2024-03-25T12:41:57Z")

</div>

Yes. There is an [additional constructor](https://artifacts.elastic.co/javadoc/co/elastic/clients/elasticsearch-java/8.12.2/co/elastic/clients/json/jackson/JacksonJsonpMapper.html#%3Cinit%3E(com.fasterxml.jackson.databind.ObjectMapper)) where you can provide a Jackson `ObjectMapper`, which you can configure at will.

---

<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 22, 2024, 12:42pm UTC](https://discuss.elastic.co/t/ignore-fields-when-indexing-using-jsondata-of/356084/7 "2024-04-22T12:42:26Z")

</div>

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