# Choosing the fields I want to return, not work

**URL:** https://discuss.elastic.co/t/choosing-the-fields-i-want-to-return-not-work/14309
**Category:** Elasticsearch
**Created:** [November 7, 2013, 7:05pm UTC](https://discuss.elastic.co/t/choosing-the-fields-i-want-to-return-not-work/14309 "2013-11-07T19:05:06Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Sanx\_El\_Santo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sanx_el_santo/32/1990_2.png) [@Sanx\_El\_Santo](https://discuss.elastic.co/u/Sanx_El_Santo)
#### Post date: [November 7, 2013, 7:05pm UTC](https://discuss.elastic.co/t/choosing-the-fields-i-want-to-return-not-work/14309/1 "2013-11-07T19:05:06Z")

</div>

Greetings to all

I need your help please

I'm testing with the following project:

curl -X DELETE localhost:9200/geonames

curl -X PUT "[http://localhost:9200/geonames](http://localhost:9200/geonames)" -d '  
{  
"settings": {  
"index": {  
"analysis": {  
"analyzer": {  
"autocomplete": {  
"tokenizer": "whitespace",  
"filter": [  
"lowercase",  
"engram"  
]  
}  
},  
"filter": {  
"engram": {  
"type": "edgeNGram",  
"min\_gram": 1,  
"max\_gram": 10  
}  
}  
}  
}  
},  
"mappings": {  
"geoname": {  
"properties": {  
"asciiname": {  
"type": "multi\_field",  
"fields": {  
"asciiname": {  
"type": "string",  
"index": "not\_analyzed",  
"store": "yes"  
},  
"autocomplete": {  
"type": "string",  
"index\_analyzer": "autocomplete",  
"index": "analyzed",  
"search\_analyzer": "standard"  
}  
}  
},  
"location" : { "type" : "geo\_point", "store":"yes",  
"index":"analyzed" }  
}  
}  
}  
}  
'

```
curl -X PUT "http://localhost:9200/geonames/geoname/1555414" -d '
{
"asciiname": "Santa Fe",
"location" : "29.01048, -101.26557"
}
'
    
curl -X PUT "http://localhost:9200/geonames/geoname/1818178" -d '
{
"asciiname": "Wardlow",
"location" : "32.55064, -115.33943"
}
'
    
curl -X PUT "http://localhost:9200/geonames/geoname/1818179" -d '
{
"asciiname": "Los Carapilas",
"location" : "32.01389, -115.01611"
}
'
    
curl -X PUT "http://localhost:9200/geonames/geoname/1818180" -d '
{
"asciiname": "Aguaje del Laretto",
"location" : "32.53306, -115.75139"
}
'
    
curl -X PUT "http://localhost:9200/geonames/geoname/1948754" -d '
{
"asciiname": "Canada El Oro",
"location" : "30.8973, -110.75184"
}
'
    
curl -X PUT "http://localhost:9200/geonames/geoname/2593121" -d '
{
"asciiname": "Paso Salinas",
"location" : "18.90224, -95.94041"
}
'
    
curl -X PUT "http://localhost:9200/geonames/geoname/3411918" -d '
{
"asciiname": "Chun Cedro",
"location" : "20.1542, -89.78498"
}
'
    
curl -X PUT "http://localhost:9200/geonames/geoname/3482868" -d '
{
"asciiname": "Tres Marias",
"location" : "22.48036, -98.01065"
}
'
    
curl -X PUT "http://localhost:9200/geonames/geoname/3482869" -d '
{
"asciiname": "Lorenzo del Real",
"location" : "22.51667, -97.91667"
}
'
    
curl -X PUT "http://localhost:9200/geonames/geoname/3482870" -d '
{
"asciiname": "El Estero",
"location" : "22.65685, -98.00748"
}
'

```

My query is as follows:

curl -XGET "localhost:9200/geonames/geoname/\_search?pretty=true" -d '  
{  
"size": 0,  
"fields" : ["asciiname","location"],  
"query": {  
"term": {  
"asciiname.autocomplete": "pa"  
}  
},  
"facets": {  
"asciiname": {  
"terms": {  
"field": "asciiname"  
}  
}  
}  
}  
'

And it works fine, returns: asciiname

But I need to return the fields:

"asciiname" and "_location_"

the book says:

With the use of the fields array in the request body, ElasticSearch allows  
us to  
define which fields should be included in the response.  
You can only return fields that are marked as stored in the mappings used  
to create the  
index.

Someone can tell me I'm missing or I'm doing wrong

Thanks for your attention

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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: [November 7, 2013, 7:25pm UTC](https://discuss.elastic.co/t/choosing-the-fields-i-want-to-return-not-work/14309/2 "2013-11-07T19:25:28Z")

</div>

You are asking for zero results ( "size": 0 ), so you are actually not  
getting either asciiname and location. You are asking for a facet on  
asciiname, so you are seeing the facet, not the fields in the hits.

Cheers,

Ivan

On Thu, Nov 7, 2013 at 11:05 AM, Sanx El Santo [hectorgool@gmail.com](mailto:hectorgool@gmail.com) wrote:

> Greetings to all
> 
> I need your help please
> 
> I'm testing with the following project:
> 
> curl -X DELETE localhost:9200/geonames
> 
> curl -X PUT "[http://localhost:9200/geonames](http://localhost:9200/geonames)" -d '  
> {  
> "settings": {  
> "index": {  
> "analysis": {  
> "analyzer": {  
> "autocomplete": {  
> "tokenizer": "whitespace",  
> "filter": [  
> "lowercase",  
> "engram"  
> ]  
> }  
> },  
> "filter": {  
> "engram": {  
> "type": "edgeNGram",  
> "min\_gram": 1,  
> "max\_gram": 10  
> }  
> }  
> }  
> }  
> },  
> "mappings": {  
> "geoname": {  
> "properties": {  
> "asciiname": {  
> "type": "multi\_field",  
> "fields": {  
> "asciiname": {  
> "type": "string",  
> "index": "not\_analyzed",  
> "store": "yes"  
> },  
> "autocomplete": {  
> "type": "string",  
> "index\_analyzer": "autocomplete",  
> "index": "analyzed",  
> "search\_analyzer": "standard"  
> }  
> }  
> },  
> "location" : { "type" : "geo\_point", "store":"yes",  
> "index":"analyzed" }  
> }  
> }  
> }  
> }  
> '
> 
> ```
> curl -X PUT "http://localhost:9200/geonames/geoname/1555414" -d '
> {
> "asciiname": "Santa Fe",
> "location" : "29.01048, -101.26557"
> }
> '
> 
> curl -X PUT "http://localhost:9200/geonames/geoname/1818178" -d '
> {
> "asciiname": "Wardlow",
> "location" : "32.55064, -115.33943"
> }
> '
> 
> curl -X PUT "http://localhost:9200/geonames/geoname/1818179" -d '
> {
> "asciiname": "Los Carapilas",
> "location" : "32.01389, -115.01611"
> }
> '
> 
> curl -X PUT "http://localhost:9200/geonames/geoname/1818180" -d '
> {
> "asciiname": "Aguaje del Laretto",
> "location" : "32.53306, -115.75139"
> }
> '
> 
> curl -X PUT "http://localhost:9200/geonames/geoname/1948754" -d '
> {
> "asciiname": "Canada El Oro",
> "location" : "30.8973, -110.75184"
> }
> '
> 
> curl -X PUT "http://localhost:9200/geonames/geoname/2593121" -d '
> {
> "asciiname": "Paso Salinas",
> "location" : "18.90224, -95.94041"
> }
> '
> 
> curl -X PUT "http://localhost:9200/geonames/geoname/3411918" -d '
> {
> "asciiname": "Chun Cedro",
> "location" : "20.1542, -89.78498"
> }
> '
> 
> curl -X PUT "http://localhost:9200/geonames/geoname/3482868" -d '
> {
> "asciiname": "Tres Marias",
> "location" : "22.48036, -98.01065"
> }
> '
> 
> curl -X PUT "http://localhost:9200/geonames/geoname/3482869" -d '
> {
> "asciiname": "Lorenzo del Real",
> "location" : "22.51667, -97.91667"
> }
> '
> 
> curl -X PUT "http://localhost:9200/geonames/geoname/3482870" -d '
> {
> "asciiname": "El Estero",
> "location" : "22.65685, -98.00748"
> }
> '
> 
> ```
> 
> My query is as follows:
> 
> curl -XGET "localhost:9200/geonames/geoname/\_search?pretty=true" -d '  
> {  
> "size": 0,  
> "fields" : ["asciiname","location"],  
> "query": {  
> "term": {  
> "asciiname.autocomplete": "pa"  
> }  
> },  
> "facets": {  
> "asciiname": {  
> "terms": {  
> "field": "asciiname"  
> }  
> }  
> }  
> }  
> '
> 
> And it works fine, returns: asciiname
> 
> But I need to return the fields:
> 
> "asciiname" and "_location_"
> 
> the book says:
> 
> With the use of the fields array in the request body, Elasticsearch allows  
> us to  
> define which fields should be included in the response.  
> You can only return fields that are marked as stored in the mappings used  
> to create the  
> index.
> 
> Someone can tell me I'm missing or I'm doing wrong
> 
> Thanks for your attention
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Sanx\_El\_Santo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sanx_el_santo/32/1990_2.png) [@Sanx\_El\_Santo](https://discuss.elastic.co/u/Sanx_El_Santo)
#### Post date: [November 7, 2013, 8:07pm UTC](https://discuss.elastic.co/t/choosing-the-fields-i-want-to-return-not-work/14309/3 "2013-11-07T20:07:05Z")

</div>

Correct!

You are right!

Thank you very much for your help Ivan!!!.

El jueves, 7 de noviembre de 2013 13:25:28 UTC-6, Ivan Brusic escribió:

> You are asking for zero results ( "size": 0 ), so you are actually not  
> getting either asciiname and location. You are asking for a facet on  
> asciiname, so you are seeing the facet, not the fields in the hits.
> 
> Cheers,
> 
> Ivan
> 
> On Thu, Nov 7, 2013 at 11:05 AM, Sanx El Santo \<[hecto...@gmail.com](mailto:hecto...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Greetings to all
> > 
> > I need your help please
> > 
> > I'm testing with the following project:
> > 
> > curl -X DELETE localhost:9200/geonames
> > 
> > curl -X PUT "[http://localhost:9200/geonames](http://localhost:9200/geonames)" -d '  
> > {  
> > "settings": {  
> > "index": {  
> > "analysis": {  
> > "analyzer": {  
> > "autocomplete": {  
> > "tokenizer": "whitespace",  
> > "filter": [  
> > "lowercase",  
> > "engram"  
> > ]  
> > }  
> > },  
> > "filter": {  
> > "engram": {  
> > "type": "edgeNGram",  
> > "min\_gram": 1,  
> > "max\_gram": 10  
> > }  
> > }  
> > }  
> > }  
> > },  
> > "mappings": {  
> > "geoname": {  
> > "properties": {  
> > "asciiname": {  
> > "type": "multi\_field",  
> > "fields": {  
> > "asciiname": {  
> > "type": "string",  
> > "index": "not\_analyzed",  
> > "store": "yes"  
> > },  
> > "autocomplete": {  
> > "type": "string",  
> > "index\_analyzer": "autocomplete",  
> > "index": "analyzed",  
> > "search\_analyzer": "standard"  
> > }  
> > }  
> > },  
> > "location" : { "type" : "geo\_point", "store":"yes",  
> > "index":"analyzed" }  
> > }  
> > }  
> > }  
> > }  
> > '
> > 
> > ```
> > curl -X PUT "http://localhost:9200/geonames/geoname/1555414" -d '
> > {
> > "asciiname": "Santa Fe",
> > "location" : "29.01048, -101.26557"
> > }
> > '
> >     
> > curl -X PUT "http://localhost:9200/geonames/geoname/1818178" -d '
> > {
> > "asciiname": "Wardlow",
> > "location" : "32.55064, -115.33943"
> > }
> > '
> >     
> > curl -X PUT "http://localhost:9200/geonames/geoname/1818179" -d '
> > {
> > "asciiname": "Los Carapilas",
> > "location" : "32.01389, -115.01611"
> > }
> > '
> >     
> > curl -X PUT "http://localhost:9200/geonames/geoname/1818180" -d '
> > {
> > "asciiname": "Aguaje del Laretto",
> > "location" : "32.53306, -115.75139"
> > }
> > '
> >     
> > curl -X PUT "http://localhost:9200/geonames/geoname/1948754" -d '
> > {
> > "asciiname": "Canada El Oro",
> > "location" : "30.8973, -110.75184"
> > }
> > '
> >     
> > curl -X PUT "http://localhost:9200/geonames/geoname/2593121" -d '
> > {
> > "asciiname": "Paso Salinas",
> > "location" : "18.90224, -95.94041"
> > }
> > '
> >     
> > curl -X PUT "http://localhost:9200/geonames/geoname/3411918" -d '
> > {
> > "asciiname": "Chun Cedro",
> > "location" : "20.1542, -89.78498"
> > }
> > '
> >     
> > curl -X PUT "http://localhost:9200/geonames/geoname/3482868" -d '
> > {
> > "asciiname": "Tres Marias",
> > "location" : "22.48036, -98.01065"
> > }
> > '
> >     
> > curl -X PUT "http://localhost:9200/geonames/geoname/3482869" -d '
> > {
> > "asciiname": "Lorenzo del Real",
> > "location" : "22.51667, -97.91667"
> > }
> > '
> >     
> > curl -X PUT "http://localhost:9200/geonames/geoname/3482870" -d '
> > {
> > "asciiname": "El Estero",
> > "location" : "22.65685, -98.00748"
> > }
> > '
> > 
> > ```
> > 
> > My query is as follows:
> > 
> > curl -XGET "localhost:9200/geonames/geoname/\_search?pretty=true" -d '  
> > {  
> > "size": 0,  
> > "fields" : ["asciiname","location"],  
> > "query": {  
> > "term": {  
> > "asciiname.autocomplete": "pa"  
> > }  
> > },  
> > "facets": {  
> > "asciiname": {  
> > "terms": {  
> > "field": "asciiname"  
> > }  
> > }  
> > }  
> > }  
> > '
> > 
> > And it works fine, returns: asciiname
> > 
> > But I need to return the fields:
> > 
> > "asciiname" and "_location_"
> > 
> > the book says:
> > 
> > With the use of the fields array in the request body, Elasticsearch  
> > allows us to  
> > define which fields should be included in the response.  
> > You can only return fields that are marked as stored in the mappings used  
> > to create the  
> > index.
> > 
> > Someone can tell me I'm missing or I'm doing wrong
> > 
> > Thanks for your attention
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:08am UTC](https://discuss.elastic.co/t/choosing-the-fields-i-want-to-return-not-work/14309/4 "2017-07-06T02:08:18Z")

</div>


