# \_geo\_distance sort and fields result

**URL:** <https://discuss.elastic.co/t/-geo-distance-sort-and-fields-result/5130>\
**Category:** Elasticsearch\
**Created:** [August 11, 2011, 7:04pm UTC](https://discuss.elastic.co/t/-geo-distance-sort-and-fields-result/5130 "2011-08-11T19:04:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![riot\_irad](https://avatars.discourse-cdn.com/v4/letter/r/b2d939/32.png) [@riot\_irad](https://discuss.elastic.co/u/riot_irad)\
**Post date:** [August 11, 2011, 7:04pm UTC](https://discuss.elastic.co/t/-geo-distance-sort-and-fields-result/5130/1 "2011-08-11T19:04:00Z")

</div>

I had a quick question on results from a particular query.

Right now we just have a bunch of test documents with a field:

"my\_point" : {  
"lat" : #,  
"lon" : #  
}

where lat is between 30 and 32, and lon is between 20 and 22 (again,  
just for testing, really).

Here's the query (without "fields" set):

{  
"size" : 10,  
"query" : {  
"query\_string" : { "query" : "name:test" }  
}  
},  
"sort" : [  
{  
"\_geo\_distance" : {  
"my\_point" : "30,20",  
"order" : "asc"  
}  
},  
"\_score"  
]  
}

The objects I get back look fine:

{... \_source:  
{ "my\_point":"lon21.3106349430918lat31.0521010454204", ... } ...}

However, if I limit the fields that are returned (adding "fields" :  
["my\_point"] to the query), the returned value of "my\_point" changes:

{... "fields":  
{"my\_point":"-89.99703053788122,-171.20920843765003" } ... }

I figure I'm just missing something simple, but thought I'd ask. Where  
is the second value coming from?

Thanks,

- Ruben

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [August 11, 2011, 8:36pm UTC](https://discuss.elastic.co/t/-geo-distance-sort-and-fields-result/5130/2 "2011-08-11T20:36:24Z")

</div>

Can you post a curl recreation including sample indexing of data? Thats  
strange that you get that...

On Thu, Aug 11, 2011 at 10:04 PM, rfq [riot.irad@gmail.com](mailto:riot.irad@gmail.com) wrote:

> I had a quick question on results from a particular query.
> 
> Right now we just have a bunch of test documents with a field:
> 
> "my\_point" : {  
> "lat" : #,  
> "lon" : #  
> }
> 
> where lat is between 30 and 32, and lon is between 20 and 22 (again,  
> just for testing, really).
> 
> Here's the query (without "fields" set):
> 
> {  
> "size" : 10,  
> "query" : {  
> "query\_string" : { "query" : "name:test" }  
> }  
> },  
> "sort" : [  
> {  
> "\_geo\_distance" : {  
> "my\_point" : "30,20",  
> "order" : "asc"  
> }  
> },  
> "\_score"  
> ]  
> }
> 
> The objects I get back look fine:
> 
> {... \_source:  
> { "my\_point":"lon21.3106349430918lat31.0521010454204", ... } ...}
> 
> However, if I limit the fields that are returned (adding "fields" :  
> ["my\_point"] to the query), the returned value of "my\_point" changes:
> 
> {... "fields":  
> {"my\_point":"-89.99703053788122,-171.20920843765003" } ... }
> 
> I figure I'm just missing something simple, but thought I'd ask. Where  
> is the second value coming from?
> 
> Thanks,
> 
> - Ruben

---

<div class="post-metadata">

**Author:** ![riot\_irad](https://avatars.discourse-cdn.com/v4/letter/r/b2d939/32.png) [@riot\_irad](https://discuss.elastic.co/u/riot_irad)\
**Post date:** [August 17, 2011, 3:06pm UTC](https://discuss.elastic.co/t/-geo-distance-sort-and-fields-result/5130/3 "2011-08-17T15:06:48Z")

</div>

Sorry for the long delay, was out of town.

I re-inserted objects and am getting similarly strange results, but in  
a different field this time.

I used the rubberband gem to create the objects:

100.times {  
obj = { "name" =\> "test", "rating\_int" =\> (rand_50).to\_i,  
"my\_point" =\> { "lat" =\> 30+20_rand/10.0, "lon" =\> 20+20\*rand/  
10.0 } }  
client.index(obj)  
}

This query ran fine this time:

curl -XGET '[http://localhost:9200/twitter/test/\_search](http://localhost:9200/twitter/test/_search)' -d '  
{  
"fields" : ["my\_point"],  
"size" : 10,  
"query" : {  
"filtered" : {  
"query" : {  
"query\_string" : { "query" : "name:test" }  
},  
"filter" : {  
"range" : { "rating\_int" : { "from": 10, "to" :20 } }  
}  
}  
},  
"sort" : [  
{  
"\_geo\_distance" : {  
"my\_point" : "30,20",  
"order" : "asc"  
}  
},  
"\_score"  
]  
}'

However, if I add the rating\_int field this time, I again see strange  
results:

curl -XGET '[http://localhost:9200/twitter/test/\_search?pretty=true](http://localhost:9200/twitter/test/_search?pretty=true)' -d  
'  
{  
"fields" : ["my\_point", "rating\_int"],  
"size" : 10,  
"query" : {  
"filtered" : {  
"query" : {  
"query\_string" : { "query" : "name:test" }  
},  
"filter" : {  
"range" : { "rating\_int" : { "from": 10, "to" :20 } }  
}  
}  
},  
"sort" : [  
{  
"\_geo\_distance" : {  
"my\_point" : "30,20",  
"order" : "asc"  
}  
},  
"\_score"  
]  
}'

Results:  
{  
"took" : 293,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 19,  
"max\_score" : null,  
"hits" : [ {  
"\_index" : "twitter",  
"\_type" : "test",  
"\_id" : "aEKDbdjBTh-E\_quJz3\_o1Q",  
"\_score" : 3.368767,  
"fields" : {  
"rating\_int" : "AAAADg==",  
"my\_point" : "30.617616303438,20.6218944909627"  
},  
"sort" : [91.09867513372355, 3.368767]  
},  
{  
"\_index" : "twitter",  
"\_type" : "test",  
"\_id" : "ALo0MEo8TuGm8lQKCeo5Dg",  
"\_score" : 3.3067431,  
"fields" : {  
"rating\_int" : "AAAAEg==",  
"my\_point" : "30.89625050032,20.1114635818668"  
},  
"sort" : [100.34228308708265, 3.3067431]  
},  
... ] }

When I do a GET on that id, though, everything looks fine:

curl -XGET '[http://localhost:9200/twitter/test/aEKDbdjBTh-E\_quJz3\_o1Q](http://localhost:9200/twitter/test/aEKDbdjBTh-E_quJz3_o1Q)?  
pretty=true'  
{  
"\_index" : "twitter",  
"\_type" : "test",  
"\_id" : "aEKDbdjBTh-E\_quJz3\_o1Q",  
"\_version" : 1,  
"exists" : true, "\_source" : {"my\_point":{"lon":  
20.6218944909627,"lat":30.617616303438},"name":"test","rating\_int":14}  
}

From the original results and now these, my first reaction is that it  
might be returning internal values from sorting?

- Ruben

On Aug 11, 4:36 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> Can you post a curl recreation including sample indexing of data? Thats  
> strange that you get that...
> 
> On Thu, Aug 11, 2011 at 10:04 PM, rfq [riot.i...@gmail.com](mailto:riot.i...@gmail.com) wrote:
> 
> > I had a quick question on results from a particular query.
> 
> > Right now we just have a bunch of test documents with a field:
> 
> > "my\_point" : {  
> > "lat" : #,  
> > "lon" : #  
> > }
> 
> > where lat is between 30 and 32, and lon is between 20 and 22 (again,  
> > just for testing, really).
> 
> > Here's the query (without "fields" set):
> 
> > {  
> > "size" : 10,  
> > "query" : {  
> > "query\_string" : { "query" : "name:test" }  
> > }  
> > },  
> > "sort" : [  
> > {  
> > "\_geo\_distance" : {  
> > "my\_point" : "30,20",  
> > "order" : "asc"  
> > }  
> > },  
> > "\_score"  
> > ]  
> > }
> 
> > The objects I get back look fine:
> 
> > {... \_source:  
> > { "my\_point":"lon21.3106349430918lat31.0521010454204", ... } ...}
> 
> > However, if I limit the fields that are returned (adding "fields" :  
> > ["my\_point"] to the query), the returned value of "my\_point" changes:
> 
> > {... "fields":  
> > {"my\_point":"-89.99703053788122,-171.20920843765003" } ... }
> 
> > I figure I'm just missing something simple, but thought I'd ask. Where  
> > is the second value coming from?
> 
> > Thanks,
> 
> > - Ruben

---

<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, 3:56am UTC](https://discuss.elastic.co/t/-geo-distance-sort-and-fields-result/5130/4 "2017-07-06T03:56:45Z")

</div>

Closed on July 6, 2017, 3:56am UTC


