# Elastic search 5.1.1 Get Specific fields

**URL:** <https://discuss.elastic.co/t/elastic-search-5-1-1-get-specific-fields/71097>\
**Category:** Elasticsearch\
**Created:** [January 10, 2017, 1:54pm UTC](https://discuss.elastic.co/t/elastic-search-5-1-1-get-specific-fields/71097 "2017-01-10T13:54:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElsayedAwd](https://avatars.discourse-cdn.com/v4/letter/e/da6949/32.png) [@ElsayedAwd](https://discuss.elastic.co/u/ElsayedAwd)\
**Post date:** [January 10, 2017, 1:54pm UTC](https://discuss.elastic.co/t/elastic-search-5-1-1-get-specific-fields/71097/1 "2017-01-10T13:54:37Z")

</div>

**I 'am using Elastic search 5.1.1** ,how to get the data of specific field of an Index .

I tried this

> POST /rawdata/feed/\_search?pretty=true  
> {  
> "\_source": ["FeatureValue", "FeatureName"],  
> "query": {  
> "match\_all":{}  
> }  
> }

and sample result is

> {  
> "took": 4,  
> "timed\_out": false,  
> "\_shards": {  
> "total": 5,  
> "successful": 5,  
> "failed": 0  
> },  
> "hits": {  
> "total": 386424,  
> "max\_score": 1,  
> "hits": [  
> {  
> "\_index": "rawdata",  
> "\_type": "feed",  
> "\_id": "591031",  
> "\_score": 1,  
> "\_source": {}  
> },

how to get all the data specified for these fields (FeatureValue,FeatureName)

---

<div class="post-metadata">

**Author:** ![jakommo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jakommo/32/6716_2.png) [@jakommo](https://discuss.elastic.co/u/jakommo)\
**Post date:** [January 10, 2017, 4:52pm UTC](https://discuss.elastic.co/t/elastic-search-5-1-1-get-specific-fields/71097/2 "2017-01-10T16:52:08Z")

</div>

It looks like it's returning documents that do not have these fields and thus the \_source is empty.  
Rather than using the match\_all, you should use an [exists query](https://www.elastic.co/guide/en/elasticsearch/reference/5.1/query-dsl-exists-query.html) , so the search hits only the docs that do have these fields.

E.g.:

> GET /logstash-000002/\_search?pretty=true  
> {  
> "\_source": [  
> "temp\_cpu"  
> ],  
> "query": {  
> "match\_all": {}  
> }  
> }

returns:

> "hits": [  
> {  
> "\_index": "logstash-000002",  
> "\_type": "test",  
> "\_id": "AVl05TMTGyqdsCsv30pl",  
> "\_score": 1,  
> "\_source": {}  
> },

while

> GET /logstash-000002/\_search?pretty=true  
> {  
> "\_source": [  
> "temp\_cpu"  
> ],  
> "query": {  
> "exists" : { "field" : "temp\_cpu" }  
> }  
> }

returns

> "hits": [  
> {  
> "\_index": "logstash-000002",  
> "\_type": "sensors",  
> "\_id": "AVl0y3pARruJw4Xh37Tf",  
> "\_score": 1,  
> "\_source": {  
> "temp\_cpu": 50  
> }  
> },  
> {

In my case, only some docs have the temp\_cpu field and the first query (match\_all) returned docs without this field, thus causing the empty \_source. While the second one only hit the docs that have this field.

---

<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:** [February 7, 2017, 4:52pm UTC](https://discuss.elastic.co/t/elastic-search-5-1-1-get-specific-fields/71097/3 "2017-02-07T16:52:33Z")

</div>

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