0

I'm trying to use a geo_point field on Heroku/Bonsai but it just doesn't want to work.

It works in local, but whenever I check the mapping for my index on Heroku/Bonsai it says my field is a string: "coordinates":{"type":"string"}

My mapping looks like this:

tire.mapping do
  ...
  indexes :coordinates, type: "geo_point", lat_lon: true
  ...
end

And my to_indexed_json like this:

def to_indexed_json
  {
    ...
    coordinates: map_marker.nil? ? nil : [map_marker.latitude, map_marker.longitude].join(','),
    ...
  }.to_json
end

In the console on Heroku I tried MyModel.mapping and MyModel.index.mapping and the first one correctly has :coordinates=>{:type=>"geo_point", :lat_lon=>true}.

Charles
  • 50,943
  • 13
  • 104
  • 142
mbillard
  • 38,386
  • 18
  • 74
  • 98
  • 1
    Have you tried deleting the index and re-indexing? Tire creates the index with mapping defined in the model only when it does not exist. Also, isn't geo point defined as `{lat: X, lon: Y}` less error prone? (Array positions, easier access in scripts, ...) – karmi Jul 06 '13 at 16:48
  • @karmi yes I tried deleting the index and recreating it, I'll try defining it as two values to see if it helps. Also, is there a proper null/empty value for geo_points? nil, {}, [], "", etc.? – mbillard Jul 07 '13 at 13:29
  • Alright, I tried defining like so `coordinates: map_marker.nil? ? nil : { lat: map_marker.latitude, lon: map_marker.longitude },`, but I get this error now: `ParsingException failed to find geo_point field [coordinates]`. Also the field is now mapped to `"coordinates":{"properties":{"lat":{"type":"double"},"lon":{"type":"double"}}}` on Heroku. – mbillard Jul 07 '13 at 18:33
  • Hmm, this is all weird. Can you try isolating the geo feature into a different model, and double-checking you drop & re-create it? And post the full code and the output of `localhost:9200//_mapping`? – karmi Jul 08 '13 at 12:33
  • Followed up with a few questions of my own via Heroku support. – Nick Zadrozny Jul 08 '13 at 14:10
  • @karmi there you go https://gist.github.com/mbillard/0de318114c0188a48faa I created a new class 'MyModel' with a single indexed attribute. The behavior is different on Heroku than on my local machine. – mbillard Jul 13 '13 at 15:22
  • @nick-zadrozny Can you verify the Bonsai end and possibly submit an answer for other folks who might this? – karmi Jul 14 '13 at 21:33
  • @karmi I have submitted a support ticket last week (monday) with Heroku and they told me that they sent the ticket to the Bonsai guys. I'll keep this updated as I get answers. – mbillard Jul 15 '13 at 03:02

1 Answers1

1

Here's how I got this to work. Index name 'myindex' type name 'myindextype'

On the local machine

curl -XGET https://[LOCAL_ES_URL]/myindex/myindextype/_mapping

save the output to a .json file. example: typedefinition.json (or hand build one)

{
  "myindextype":{
    "properties":{
      "dataone":{"type":"string"},
      "datatwo":{"type":"double"},
      "location":{"type":"geo_point"},
      "datathree":{"type":"long"},
      "datafour":{"type":"string"}
    }
  }
}

On heroku enter the command

heroku config

and get the BONSAI_URL. Put it in the follwoing commands in place of [BONSAI_URL]. (https://asdfasdfdsf:asdfadf@asdfasdfasdf.us-east-1.bonsai.io/myindex)

curl -XDELETE https://[BONSAI_URL]/myindex
curl -XPOST https://[BONSAI_URL]/myindex
curl -XPUT -d@typedefinition.json https://[BONSAI_URL]/myindex/myindextype/_mapping 
curl -XGET https://[BONSAI_URL]/myindex/myindextype/_mapping
  1. Deletes the indes if it exists.
  2. Createds an empty index.
  3. Uses the .json file as a definition for mapping.
  4. Get the new mapping to make sure it worked.
Diver
  • 1,568
  • 2
  • 17
  • 32