# Search for a field and get only the JsonObejct below it

**URL:** <https://discuss.elastic.co/t/search-for-a-field-and-get-only-the-jsonobejct-below-it/190226>\
**Category:** Elasticsearch\
**Created:** [July 12, 2019, 11:57am UTC](https://discuss.elastic.co/t/search-for-a-field-and-get-only-the-jsonobejct-below-it/190226 "2019-07-12T11:57:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nils\_Friederich](https://avatars.discourse-cdn.com/v4/letter/n/85e7bf/32.png) [@Nils\_Friederich](https://discuss.elastic.co/u/Nils_Friederich)\
**Post date:** [July 12, 2019, 11:57am UTC](https://discuss.elastic.co/t/search-for-a-field-and-get-only-the-jsonobejct-below-it/190226/1 "2019-07-12T11:57:03Z")

</div>

Hello everyone!  
I'm quite new to ES and have a question that's been bothering me for a few days:  
I'm trying to search for a certain field and just want to output the Json-Object below it. Here is a short example:

**-data:**

....  
source:  
{  
"Test":  
{"ABCD":  
[ { "Fruit":  
[ {"Type": "Banana"},  
{"Type": "Cherry"}  
....  
]},  
{"Vegetables":  
[{"Type": "Carrot"}]  
...  
}]  
}  
}

**-desired output:**  
{ "Fruit":  
[ {"Type": "Banana"},  
{"Type": "Cherry"}]}

I use the java High-Level-api and have already tried several things. E.G.

```
SearchResponse sr = client.getClient().search(
                    new SearchRequest(index).searchType(SearchType.DFS_QUERY_THEN_FETCH)
                    .source(new SearchSourceBuilder()
                            .fetchSource(new String[] {"Test.ABCD.*.Fruit"}, null)), RequestOptions.DEFAULT);

```

But here, for example, I get the output:  
{  
"Test":  
{"ABCD":  
[ { "Fruit":  
[ {"Type": "Banana"},  
{"Type": "Cherry"}  
]  
}]  
}  
}  
But I'd like only `{ "Fruit": [{"Type": "Banana"},{"Type": "Cherry"}]}`  
Is that possible somehow? (I already tried it with thisscript:

`.scriptField("Fruit", new Script("params['_source']['Test']['ABCD']['Fruit']"`

, but I didn't manage that either...

Thank you!! 🙂

---

<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:** [August 9, 2019, 11:57am UTC](https://discuss.elastic.co/t/search-for-a-field-and-get-only-the-jsonobejct-below-it/190226/2 "2019-08-09T11:57:07Z")

</div>

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