# How to control what fields returned in response

**URL:** https://discuss.elastic.co/t/how-to-control-what-fields-returned-in-response/57426
**Category:** Elasticsearch
**Created:** [August 7, 2016, 3:38pm UTC](https://discuss.elastic.co/t/how-to-control-what-fields-returned-in-response/57426 "2016-08-07T15:38:52Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![cassiopeia](https://avatars.discourse-cdn.com/v4/letter/c/6de8d8/32.png) [@cassiopeia](https://discuss.elastic.co/u/cassiopeia)
#### Post date: [August 7, 2016, 3:38pm UTC](https://discuss.elastic.co/t/how-to-control-what-fields-returned-in-response/57426/1 "2016-08-07T15:38:52Z")

</div>

Hi,

my response from a search API looks like this

```
{  
    "took":88,
    "timed_out":false,
    "_shards":{  
        "total":3,
        "successful":3,
        "failed":0
    },
    "hits":{  
        "total":2,
        "max_score":1.0,
        "hits":[  
            {  
                "_index":"myindex",
                "_type":"mytype",
                "_id":"first",
                "_score":1.0,
                "fields":{  
                    "name":["John Smith"]
                }
            },
            {  
                "_index":"myindex",
                "_type":"mytype",
                "_id":"second",
                "_score":1.0,
                "fields":{  
                    "name":["John Doe"]
                }
            }
        ]
    }
}

```

I want the response not to include \_index, \_type, \_score in each hits element.  
how do I do this?  
Thanks

---

<div class="post-metadata">

### Author: ![taras](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/taras/32/507_2.png) [@taras](https://discuss.elastic.co/u/taras)
#### Post date: [August 8, 2016, 2:34pm UTC](https://discuss.elastic.co/t/how-to-control-what-fields-returned-in-response/57426/2 "2016-08-08T14:34:04Z")

</div>

There are a few basic fields which are always returned with a search hit. That includes \_\_index, \_type, _id_. If you wish to turn off score, you can specify query argument: [track\_scores=false](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-uri-request.html#_parameters_4)

If you're looking for a very _lean_ interface to use externally, you'd want to write a simple proxy client. In fact it would be advisable to write a proxy client for any external communication period in order to control serialization, business logic, and security.

---

<div class="post-metadata">

### Author: ![cassiopeia](https://avatars.discourse-cdn.com/v4/letter/c/6de8d8/32.png) [@cassiopeia](https://discuss.elastic.co/u/cassiopeia)
#### Post date: [August 9, 2016, 2:52pm UTC](https://discuss.elastic.co/t/how-to-control-what-fields-returned-in-response/57426/3 "2016-08-09T14:52:28Z")

</div>

so, there's just no way to get rid of \_index and \_type?

---

<div class="post-metadata">

### Author: ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)
#### Post date: [August 9, 2016, 2:56pm UTC](https://discuss.elastic.co/t/how-to-control-what-fields-returned-in-response/57426/4 "2016-08-09T14:56:55Z")

</div>

You can use [response filtering](https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#_response_filtering) and specify the `filter_path` parameter in your query:

Using

```
GET _search?filter_path=hits.hits.fields

```

You'll only get this in your response

```
{  
    "hits":{  
        "hits":[  
            {  
                "fields":{  
                    "name":["John Smith"]
                }
            },
            {  
                "fields":{  
                    "name":["John Doe"]
                }
            }
        ]
    }
}
```

---

<div class="post-metadata">

### Author: ![cassiopeia](https://avatars.discourse-cdn.com/v4/letter/c/6de8d8/32.png) [@cassiopeia](https://discuss.elastic.co/u/cassiopeia)
#### Post date: [August 10, 2016, 9:08am UTC](https://discuss.elastic.co/t/how-to-control-what-fields-returned-in-response/57426/5 "2016-08-10T09:08:21Z")

</div>

Hi Val,

the code doesnt work. it'll still return \_index and \_type and \_score in every hits  
I;ve uploaded in [https://github.com/aws-es-user/aws-es](https://github.com/aws-es-user/aws-es)  
Main method is in ElasticSearchService. You'll need an AWS account to test

Thanks

---

<div class="post-metadata">

### Author: ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)
#### Post date: [August 10, 2016, 9:10am UTC](https://discuss.elastic.co/t/how-to-control-what-fields-returned-in-response/57426/6 "2016-08-10T09:10:22Z")

</div>

You're using `filterPath` instead of `filter_path`.  
See here: [https://github.com/aws-es-user/aws-es/blob/master/src/main/java/com/awses/main/ElasticSearchService.java#L22](https://github.com/aws-es-user/aws-es/blob/master/src/main/java/com/awses/main/ElasticSearchService.java#L22)

Please fix and try again.

---

<div class="post-metadata">

### Author: ![cassiopeia](https://avatars.discourse-cdn.com/v4/letter/c/6de8d8/32.png) [@cassiopeia](https://discuss.elastic.co/u/cassiopeia)
#### Post date: [August 10, 2016, 9:12am UTC](https://discuss.elastic.co/t/how-to-control-what-fields-returned-in-response/57426/7 "2016-08-10T09:12:39Z")

</div>

dear God, that's so embarassing. Thank you so much for the help.

---

<div class="post-metadata">

### Author: ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)
#### Post date: [August 10, 2016, 9:13am UTC](https://discuss.elastic.co/t/how-to-control-what-fields-returned-in-response/57426/8 "2016-08-10T09:13:33Z")

</div>

No problem, my pleasure!

---

<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: [July 5, 2017, 10:28pm UTC](https://discuss.elastic.co/t/how-to-control-what-fields-returned-in-response/57426/9 "2017-07-05T22:28:50Z")

</div>


