Re: sorting by _geo_distance returns the wrong order

2014-10-14 Thread Sören Martius
i solved it myself. I needed to set slug in my mappings to "not_analyzed" 
and i change the query to this one:

{
  "from": 0,
  "size": 3,
  "query": {
"filtered": {
  "query": {
"bool": {
  "must_not": [
{
  "match": {
"slug": "adlon-hotel"
  }
}
  ]
}
  },
  "filter": {
"exists": {
  "field": "pin"
}
  }
}
  },
  "sort": [
{
  "_geo_distance": {
"pin": {
  "lat": 52.51515,
  "lon": 13.38019
},
"order": "asc",
"unit": "km",
"distance_type": "arc"
  }
}
  ]
}


Am Dienstag, 14. Oktober 2014 10:04:00 UTC+2 schrieb Sören Martius:
>
> Hello,
>
> In my Index i have several locations with some information and geo data. 
> In the detail view of an location i try to query for locations which are 
> near by the current one.
> I am confused, cause my query does not return the correct order of 
> locations. If you check the geo locations you will see, that the order is 
> wrong.
> The bool query is there for preventing getting the current location in the 
> result ( identified by the locations slug ).
>
> In the following example, please notice that the query is run with the geo 
> point of "adlon hotel", so the first returned location should be "Hotel 
> Prens Berlin Kreuzberg".
>
> Here is the query:
>
> curl -XGET 'http://localhost:9200/search/location/_search' -d 
> '{"sort":[{"_geo_distance":{"pin":[52.51515,13.38019],"order":"asc","unit":"km","distance_type":"arc"}}],"query":{"bool":{"must_not":[{"match":{"slug":"adlon-hotel"}}]}},"size":3}'
>
>
> Here is my mapping: 
>
>
>
>
>
>
>
>
>
> {
>
>   "search" : {
>
> "mappings" : {
>
>   "location" : {
>
> "_meta" : {
>
>   "model" : 
> "AnchorVentures\\Bundle\\LocationBundle\\Entity\\Location"
>
> },
>
> "_all" : {
>
>   "auto_boost" : true
>
> },
>
> "properties" : {
>
>   "address" : {
>
> "properties" : {
>
>   "pin" : {
>
> "type" : "geo_point",
>
> "store" : true,
>
> "lat_lon" : true
>
>   },
>
>   "zipcode" : {
>
> "type" : "string",
>
> "store" : true
>
>   }
>
> }
>
>   },
>
>   "city" : {
>
> "type" : "nested",
>
> "properties" : {
>
>   "name" : {
>
> "type" : "string",
>
> "boost" : 10.0,
>
> "store" : true
>
>   }
>
> }
>
>   },
>
>   "countedRatings" : {
>
> "type" : "string",
>
> "store" : true
>
>   },
>
>   "createdAt" : {
>
> "type" : "string",
>
> "store" : true
>
>   },
>
>   "details" : {
>
> "type" : "nested",
>
> "properties" : {
>
>   "guestsQuantity" : {
>
> "type" : "string",
>
> "store" : true
>
>   },
>
>   "isCatering" : {
>
> "type" : "string",
>
> "store" : true
>
>   },
>
>   "isIndoor" : {
>
> "type" : "string",
>
> "store" : true
>
>   },
>
>   "isOutdoor" : {
>
> "type" : "string",
>
> "store" : true
>
>   },
>
>   "isOvernightAccommodation" : {
>
> "type" : "string",
>
> "store" : true
>
>   },
>
>   "price" : {
>
> "type" : "string",
>
> "store" : true
>
>   },
>
>   "roomQuantity" : {
>
> "type" : "string",
>
> "store" : true
>
>   }
>
> }
>
>   },
>
>   "name" : {
>
> "type" : "string",
>
> "store" : true
>
>   },
>
>   "slug" : {
>
> "type" : "string",
>
> "store" : true
>
>   },
>
>   "updatedAt" : {
> https://groups.google.com/d/msgid/elasticsearch/1438f59c-e889-42b3-ab98-274a0c7b4d48%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


sorting by _geo_distance returns the wrong order

2014-10-14 Thread Sören Martius
Hello,

In my Index i have several locations with some information and geo data. In 
the detail view of an location i try to query for locations which are near 
by the current one.
I am confused, cause my query does not return the correct order of 
locations. If you check the geo locations you will see, that the order is 
wrong.
The bool query is there for preventing getting the current location in the 
result ( identified by the locations slug ).

In the following example, please notice that the query is run with the geo 
point of "adlon hotel", so the first returned location should be "Hotel 
Prens Berlin Kreuzberg".

Here is the query:

curl -XGET 'http://localhost:9200/search/location/_search' -d 
'{"sort":[{"_geo_distance":{"pin":[52.51515,13.38019],"order":"asc","unit":"km","distance_type":"arc"}}],"query":{"bool":{"must_not":[{"match":{"slug":"adlon-hotel"}}]}},"size":3}'


Here is my mapping: 









{

  "search" : {

"mappings" : {

  "location" : {

"_meta" : {

  "model" : 
"AnchorVentures\\Bundle\\LocationBundle\\Entity\\Location"

},

"_all" : {

  "auto_boost" : true

},

"properties" : {

  "address" : {

"properties" : {

  "pin" : {

"type" : "geo_point",

"store" : true,

"lat_lon" : true

  },

  "zipcode" : {

"type" : "string",

"store" : true

  }

}

  },

  "city" : {

"type" : "nested",

"properties" : {

  "name" : {

"type" : "string",

"boost" : 10.0,

"store" : true

  }

}

  },

  "countedRatings" : {

"type" : "string",

"store" : true

  },

  "createdAt" : {

"type" : "string",

"store" : true

  },

  "details" : {

"type" : "nested",

"properties" : {

  "guestsQuantity" : {

"type" : "string",

"store" : true

  },

  "isCatering" : {

"type" : "string",

"store" : true

  },

  "isIndoor" : {

"type" : "string",

"store" : true

  },

  "isOutdoor" : {

"type" : "string",

"store" : true

  },

  "isOvernightAccommodation" : {

"type" : "string",

"store" : true

  },

  "price" : {

"type" : "string",

"store" : true

  },

  "roomQuantity" : {

"type" : "string",

"store" : true

  }

}

  },

  "name" : {

"type" : "string",

"store" : true

  },

  "slug" : {

"type" : "string",

"store" : true

  },

  "updatedAt" : {

"type" : "string",

"store" : true

  }

}

  }

}

  }

}


And finally some documents









{

  "took" : 2,

  "timed_out" : false,

  "_shards" : {

"total" : 5,

"successful" : 5,

"failed" : 0

  },

  "hits" : {

"total" : 10,

"max_score" : 1.0,

"hits" : [ {

  "_index" : "search",

  "_type" : "location",

  "_id" : "207",

  "_score" : 1.0,

  "_source":{"name":"Badeschiff","slug":"badeschiff","countedRatings":0,
"createdAt":"2014-10-13T10:40:58+02:00","updatedAt":
"2014-10-13T10:40:58+02:00","details":{"price":1,"isIndoor":true,"isOutdoor"
:true,"isCatering":true,"isOvernightAccommodation":false,"roomQuantity":1,
"guestsQuantity":50},"city":{"name":"Berlin"},"address":{"zipcode":"12435",
"pin":"52.4970479,13.4525442"}}

}, {

  "_index" : "search",

  "_type" : "location",

  "_id" : "214",

  "_score" : 1.0,

  "_source":{"name":"Le Plat du Jour","slug":"le-plat-du-jour",
"countedRatings":0,"createdAt":"2014-10-13T10:40:58+02:00","updatedAt":
"2014-10-13T10:40:58+02:00","details":{"price":5,"isIndoor":true,"isOutdoor"
:true,"isCatering":true,"isOvernightAccommodation":false,"roomQuantity":4,
"guestsQuantity":50},"city":{"name":"Hamburg"},"address":{"zipcode":"20095",
"pin":"53.54911,9.99439"}}

}, {

  "_index" : "search",

  "_type" : "location",

  "_id" : "206",

  "_score" : 1.0,

  "_source":{"name":"Spreequartier","slug":"spreequartier",
"countedRatings":0,"createdAt":"2014-10-13T10:40:58+02:00","updatedAt":
"2014-10-13T10:40:58+02:00","details":{"price":5,"isIndoor":true,"isOutdoor"
:true,"isCatering":true,"isOvernightAccommodation":false,"roomQuantity":3,
"guestsQuantity":80},"city":{"name":"Berlin"},"address":{"zipcode":"10245",
"pin":