# Formatting Enriched field in Java

**URL:** <https://discuss.elastic.co/t/formatting-enriched-field-in-java/363135>\
**Category:** Elasticsearch\
**Created:** [July 15, 2024, 10:43am UTC](https://discuss.elastic.co/t/formatting-enriched-field-in-java/363135 "2024-07-15T10:43:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![always\_improving123](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@always\_improving123](https://discuss.elastic.co/u/always_improving123)\
**Post date:** [July 15, 2024, 10:43am UTC](https://discuss.elastic.co/t/formatting-enriched-field-in-java/363135/1 "2024-07-15T10:43:35Z")

</div>

Hello,

I have implemented an enrich processor and I am trying to properly format the enrich index’s docs. For example, I have a source index with a nationality and an average height. I want to enrich an index that only contains nationality data with the average height data from the source index. What is currently happening is that in the enrich index, an object of both nationality and height data is set into the “height” data field. Instead of this, I want to format it so only the true height data is set to the “height” field of the enrich data. (Ex “height” : “5.11” instead of “height” : { “nationality” : “…..”, “height” : “5.11” } ). This is all being done in **Java**. I am wondering if this is possible or if the limitations of the enrich processor makes this unattainable. Thanks!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 15, 2024, 11:49am UTC](https://discuss.elastic.co/t/formatting-enriched-field-in-java/363135/2 "2024-07-15T11:49:10Z")

</div>

You could then add a [rename processor](https://www.elastic.co/guide/en/elasticsearch/reference/current/rename-processor.html) to rename the `height.height` field to `height`.

---

<div class="post-metadata">

**Author:** ![always\_improving123](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@always\_improving123](https://discuss.elastic.co/u/always_improving123)\
**Post date:** [July 16, 2024, 3:38am UTC](https://discuss.elastic.co/t/formatting-enriched-field-in-java/363135/3 "2024-07-16T03:38:55Z")

</div>

Hello Again,

Thanks for sending in a reply to my question.  
I have been trying to implement the rename processor with no success. Here is my implementation in java:

```auto
Processor renameProcessor = new Processor.Builder()
	            .rename(r -> r
	                .field("height.height")
	                .targetField("height")
	                .ignoreMissing(true)
	                .ignoreFailure(true))
	            .build();

```

But the outcome is still not a flat height field. I am creating a pipeline via a PutPipelineRequest object and i specify when i would like my processor to be executed in this declaration, the order is enrichProcessor, scriptProcessor, removeProcessor, renameProcessor. I have tried switching the order with no success. Is there another Processor/alternate implementation that can aid me to accomplish my goal?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 16, 2024, 10:19am UTC](https://discuss.elastic.co/t/formatting-enriched-field-in-java/363135/4 "2024-07-16T10:19:20Z")

</div>

Could you share a full example using the simulate API from the dev console?  
So we can better understand what your problem is.

---

<div class="post-metadata">

**Author:** ![always\_improving123](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@always\_improving123](https://discuss.elastic.co/u/always_improving123)\
**Post date:** [July 18, 2024, 3:34am UTC](https://discuss.elastic.co/t/formatting-enriched-field-in-java/363135/5 "2024-07-18T03:34:55Z")

</div>

Hello Again,

Sorry for the late response. Here is some info that will hopefully help you better understand my problem. Here is a simplified example on what mine looks like.

```auto
 "_index" : "male_heights",
        "_id" : "German|5.11_M",
        "_score" : 1.0,
        "_source" : {
          "nationality" : "German",
          "height" : {
            "height" : "5.11"
          },
          "gender" : "M",
        }

```

But i need it to look like this.

```auto
"_index" : "male_heights",
        "_id" : "German|5.11_M",
        "_score" : 1.0,
        "_source" : {
          "nationality" : "German",
           "height" : "5.11",
          "gender" : "M",
        }

```

Please let me know if you need anymore information. Thanks for your help!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 18, 2024, 7:24am UTC](https://discuss.elastic.co/t/formatting-enriched-field-in-java/363135/6 "2024-07-18T07:24:16Z")

</div>

What does not work with what I proposed here?

> [@dadoonet](#):
>
> You could then add a [rename processor](https://www.elastic.co/guide/en/elasticsearch/reference/current/rename-processor.html) to rename the `height.height` field to `height`.

Could you share a [full simulate call](https://www.elastic.co/guide/en/elasticsearch/reference/current/simulate-pipeline-api.html#simulate-pipeline-api-request-body-ex)?
