# How can we eliminate the extra fields from elasticsearch query result?

**URL:** <https://discuss.elastic.co/t/how-can-we-eliminate-the-extra-fields-from-elasticsearch-query-result/163462>\
**Category:** Elasticsearch\
**Created:** [January 9, 2019, 7:29am UTC](https://discuss.elastic.co/t/how-can-we-eliminate-the-extra-fields-from-elasticsearch-query-result/163462 "2019-01-09T07:29:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinodanumarla](https://avatars.discourse-cdn.com/v4/letter/v/a698b9/32.png) [@vinodanumarla](https://discuss.elastic.co/u/vinodanumarla)\
**Post date:** [January 9, 2019, 7:29am UTC](https://discuss.elastic.co/t/how-can-we-eliminate-the-extra-fields-from-elasticsearch-query-result/163462/1 "2019-01-09T07:29:29Z")

</div>

{  
"\_id": "0048160a463a73faaa6c90f5af027772",

"\_rev": "1-ff6255309f1b873a4e482310843a8a15",

"timestamp": 1496275536932.6602,

"results": {

```
"lines": {

  "S1": [

    {

      "needed_key": "foo",

      "not_needed_key": 1

    },
{

      "needed_key": "bar",

      "not_needed_key": 1

    },

    {

      "needed_key": "foo_bar",

      "not_needed_key": 1

    }

  ],

  ...

}

```

},

"station": "5002270",

"another\_not\_needed\_key": "something"

}

How can I write an elasticsearch query to get the output by eliminating the unnecessary fields from above document?

Query Which I have used to return result :-  
GET Index/\_search  
{  
"query": {  
"bool": {  
"filter": {  
"term": {  
"results.lines.S1.needed\_key":"foo"  
}  
}  
}  
}  
}

Below is my expected output.

{  
"\_id": "fd298368a7a344b217698677f3f5a07d",  
"timestamp": 1496275536932.6602,  
"station": "5002270",  
"S1": {  
"needed\_key": "foo",  
}  
}

Below is my Actual output :  
{  
"\_id": "0048160a463a73faaa6c90f5af027772",

"\_rev": "1-ff6255309f1b873a4e482310843a8a15",

"timestamp": 1496275536932.6602,

"results": {

```
"lines": {

  "S1": [

    {

      "needed_key": "foo",

    },
     {

      "needed_key": "bar",

    },
    {

      "needed_key": "foo_bar",

    }

  ],
  ...

}

```

},

"station": "5002270",

"another\_not\_needed\_key": "something"

}

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [January 9, 2019, 7:33am UTC](https://discuss.elastic.co/t/how-can-we-eliminate-the-extra-fields-from-elasticsearch-query-result/163462/2 "2019-01-09T07:33:07Z")

</div>

This seems to be a duplicate of [this thread](https://discuss.elastic.co/t/how-can-we-eliminate-the-root-structure-for-nested-elements-in-the-query-result-in-elasticsearch/163308). Please do not open multiple threads for the same question.

---

<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:** [January 9, 2019, 9:31am UTC](https://discuss.elastic.co/t/how-can-we-eliminate-the-extra-fields-from-elasticsearch-query-result/163462/3 "2019-01-09T09:31:14Z")

</div>


