# How to limit fields of response doc when I search certain keyword?

**URL:** <https://discuss.elastic.co/t/how-to-limit-fields-of-response-doc-when-i-search-certain-keyword/18484>\
**Category:** Elasticsearch\
**Created:** [July 5, 2014, 9:12am UTC](https://discuss.elastic.co/t/how-to-limit-fields-of-response-doc-when-i-search-certain-keyword/18484 "2014-07-05T09:12:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![11158](https://avatars.discourse-cdn.com/v4/letter/1/d9b06d/32.png) [@11158](https://discuss.elastic.co/u/11158)\
**Post date:** [July 5, 2014, 9:12am UTC](https://discuss.elastic.co/t/how-to-limit-fields-of-response-doc-when-i-search-certain-keyword/18484/1 "2014-07-05T09:12:13Z")

</div>

Dear all:  
There is a reasonable need, but I don't find a solve in official doc or  
book, can you help me?

I have a large set of docs, which contains a lot of fields, such as:  
{  
"id": 1404999597,  
"idstr": "1404999597",  
"class": 1,  
"screen\_name": "主播梦桐",  
"name": "主播梦桐",  
"province": "11",  
"city": "1000",  
"location": "北京",  
"description": "在主流与非主流之间徘徊",  
"url": "",  
"profile\_image\_url": "http://tp2.sinaimg.cn/1404999597/50/5642385629/0",  
"profile\_url": "u/1404999597",  
"domain": "",  
"weihao": "",  
"gender": "f",  
"followers\_count": 1030710,  
"friends\_count": 272,  
"statuses\_count": 1519,  
"favourites\_count": 90,  
"created\_at": "Wed Mar 23 23:59:40 +0800 2011",  
"following": false,  
"allow\_all\_act\_msg": false,  
"geo\_enabled": false,  
"verified": true,  
"verified\_type": 0,  
"remark": "",  
"status": {  
"created\_at": "Tue Jul 01 13:17:55 +0800 2014",  
"id": 3727513249206064,  
"mid": "3727513249206064",  
"idstr": "3727513249206064",  
"text": "听到她的声音，我更相信她和荷西在天堂，依旧幸福着。 //@东方尔雅:现在这种纯真的爱情还好找吗？ //@晓玲-有话说:[心]",  
"source": "\<a href="http://app.weibo.com/t/feed/9ksdit"  
rel="nofollow"\>iPhone客户端",  
"favorited": false,  
"truncated": false,  
"in\_reply\_to\_status\_id": "",  
"in\_reply\_to\_user\_id": "",  
"in\_reply\_to\_screen\_name": "",  
"pic\_urls": [],  
"geo": null,  
"reposts\_count": 0,  
"comments\_count": 0,  
"attitudes\_count": 0,  
"mlevel": 0,  
"visible": {  
"type": 0,  
"list\_id": 0  
},  
"darwin\_tags": []  
},  
"ptype": 1,  
"allow\_all\_comment": true,  
"avatar\_large": "[http://tp2.sinaimg.cn/1404999597/180/5642385629/0](http://tp2.sinaimg.cn/1404999597/180/5642385629/0)",  
"avatar\_hd": "[http://tp2.sinaimg.cn/1404999597/180/5642385629/0](http://tp2.sinaimg.cn/1404999597/180/5642385629/0)",  
"verified\_reason": "电视台主持人梦桐",  
"verified\_trade": "",  
"verified\_reason\_url": "",  
"verified\_source": "",  
"verified\_source\_url": "",  
"follow\_me": false,  
"online\_status": 0,  
"bi\_followers\_count": 167,  
"lang": "zh-cn",  
"star": 0,  
"mbtype": 0,  
"mbrank": 0,  
"block\_word": 0,  
"block\_app": 0,  
"ability\_tags": "主持人",  
"worldcup\_guess": 0  
}

My problem is when I search(or scan & scroll) a certain field, for example  
"city"=1000(1000 is its city code, which refer to a city name), there maybe  
10000 results are returned. But my goal is detect how gender of this city's  
person is distributed in my website, I don't need so many information  
except "gender" field. What method can I do for excluding meaningless data  
from the response JSON before they are returned? Because there are so many  
similar tasks for me, transmitting the entire doc will spend lots of time  
and bandwidth, and I have to trim the additional date in myself program, it  
also wast CPU time in local computer. So if you know how to deal with this  
need, pleas teach it to my. Thank you!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/2a01d5f4-67a5-493a-8e35-6f9a40a9998b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2a01d5f4-67a5-493a-8e35-6f9a40a9998b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [July 7, 2014, 9:42pm UTC](https://discuss.elastic.co/t/how-to-limit-fields-of-response-doc-when-i-search-certain-keyword/18484/2 "2014-07-07T21:42:45Z")

</div>

If I understand you correctly, you want to view the distribution of gender  
based on the results of a query? In that case, you want to look into  
aggregations, which work on top of the result set that is returned.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Here is a query that should work with your basic use case. Substitute  
aggregations for facets if you have a newer version of Elasticsearch.

{  
"size": 0,  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
},  
"filter": {  
"term": {  
"city": "1000"  
}  
}  
}  
},  
"facets": {  
"gender": {  
"terms": {  
"field": "gender"  
}  
}  
}  
}

--  
Ivan

On Sat, Jul 5, 2014 at 2:12 AM, 纪路 [magievanerv@gmail.com](mailto:magievanerv@gmail.com) wrote:

> Dear all:  
> There is a reasonable need, but I don't find a solve in official doc or  
> book, can you help me?
> 
> I have a large set of docs, which contains a lot of fields, such as:  
> {  
> "id": 1404999597,  
> "idstr": "1404999597",  
> "class": 1,  
> "screen\_name": "主播梦桐",  
> "name": "主播梦桐",  
> "province": "11",  
> "city": "1000",  
> "location": "北京",  
> "description": "在主流与非主流之间徘徊",  
> "url": "",  
> "profile\_image\_url": "[http://tp2.sinaimg.cn/1404999597/50/5642385629/0](http://tp2.sinaimg.cn/1404999597/50/5642385629/0)",  
> "profile\_url": "u/1404999597",  
> "domain": "",  
> "weihao": "",  
> "gender": "f",  
> "followers\_count": 1030710,  
> "friends\_count": 272,  
> "statuses\_count": 1519,  
> "favourites\_count": 90,  
> "created\_at": "Wed Mar 23 23:59:40 +0800 2011",  
> "following": false,  
> "allow\_all\_act\_msg": false,  
> "geo\_enabled": false,  
> "verified": true,  
> "verified\_type": 0,  
> "remark": "",  
> "status": {  
> "created\_at": "Tue Jul 01 13:17:55 +0800 2014",  
> "id": 3727513249206064,  
> "mid": "3727513249206064",  
> "idstr": "3727513249206064",  
> "text": "听到她的声音，我更相信她和荷西在天堂，依旧幸福着。 //@东方尔雅:现在这种纯真的爱情还好找吗？ //@晓玲-有话说:[心]",  
> "source": "\<a href="[http://app.weibo.com/t/feed/9ksdit\](http://app.weibo.com/t/feed/9ksdit%5C)"  
> rel="nofollow"\>iPhone客户端",  
> "favorited": false,  
> "truncated": false,  
> "in\_reply\_to\_status\_id": "",  
> "in\_reply\_to\_user\_id": "",  
> "in\_reply\_to\_screen\_name": "",  
> "pic\_urls": ,  
> "geo": null,  
> "reposts\_count": 0,  
> "comments\_count": 0,  
> "attitudes\_count": 0,  
> "mlevel": 0,  
> "visible": {  
> "type": 0,  
> "list\_id": 0  
> },  
> "darwin\_tags":   
> },  
> "ptype": 1,  
> "allow\_all\_comment": true,  
> "avatar\_large": "[http://tp2.sinaimg.cn/1404999597/180/5642385629/0](http://tp2.sinaimg.cn/1404999597/180/5642385629/0)",  
> "avatar\_hd": "[http://tp2.sinaimg.cn/1404999597/180/5642385629/0](http://tp2.sinaimg.cn/1404999597/180/5642385629/0)",  
> "verified\_reason": "电视台主持人梦桐",  
> "verified\_trade": "",  
> "verified\_reason\_url": "",  
> "verified\_source": "",  
> "verified\_source\_url": "",  
> "follow\_me": false,  
> "online\_status": 0,  
> "bi\_followers\_count": 167,  
> "lang": "zh-cn",  
> "star": 0,  
> "mbtype": 0,  
> "mbrank": 0,  
> "block\_word": 0,  
> "block\_app": 0,  
> "ability\_tags": "主持人",  
> "worldcup\_guess": 0  
> }
> 
> My problem is when I search(or scan & scroll) a certain field, for example  
> "city"=1000(1000 is its city code, which refer to a city name), there maybe  
> 10000 results are returned. But my goal is detect how gender of this city's  
> person is distributed in my website, I don't need so many information  
> except "gender" field. What method can I do for excluding meaningless data  
> from the response JSON before they are returned? Because there are so many  
> similar tasks for me, transmitting the entire doc will spend lots of time  
> and bandwidth, and I have to trim the additional date in myself program, it  
> also wast CPU time in local computer. So if you know how to deal with this  
> need, pleas teach it to my. Thank you!
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/2a01d5f4-67a5-493a-8e35-6f9a40a9998b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2a01d5f4-67a5-493a-8e35-6f9a40a9998b%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/2a01d5f4-67a5-493a-8e35-6f9a40a9998b%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/2a01d5f4-67a5-493a-8e35-6f9a40a9998b%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCYFj8LGp%2B1jTaER10DrPbGVcbfnatkm8%2BNrOEvzbqfaQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCYFj8LGp%2B1jTaER10DrPbGVcbfnatkm8%2BNrOEvzbqfaQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:17am UTC](https://discuss.elastic.co/t/how-to-limit-fields-of-response-doc-when-i-search-certain-keyword/18484/3 "2017-07-06T01:17:29Z")

</div>


