How to specify a geo_point mapping


(kash badami) #1

OK, so I have tried unsuccessfully for 2 days now to create a custom mapping for a geo_point field. According to the docs, I can put a file under config/mapping/_default to specify a custom mapping for a geo_point field. So I did like this:

config/mappings/_default/golfcourse.json

  "golfcourse":{
     "properties":{
        "par":{
           "type":"long"
        },
        "phone":{
           "type":"string"
        },
        "numholes":{
           "type":"long"
        },
        "lon":{
           "type":"double"
        },
        "location":{
           "properties":{
            "type" : "geo_point"
           }
        },
        "address":{
           "type":"string"
        },
        "name":{
           "type":"string"
        },
        "state":{
           "type":"string"
        },
        "lat":{
           "type":"double"
        },
        "coursetype":{
           "type":"string"
        },
        "city":{
           "type":"string"
        }
     }
  }

}

Then I index golfcourses based on this schema. When I access the mapping like this http://localhost:8080/index/golfcourse/_mapping I get this:

{

index: { }

}

No mapping!

When I query, the index/golfcourse type I get results for a normal query like this:

http://localhost:9200/index/golfcourse/_search?q=reston

When I run a geo query like this:

curl -XGET http://localhost:9200/index/golfcourse/_search -d '
{
query : {
filtered : {
query : {
match_all : { }
}
,
filter : {
geo_distance : {
distance : "30mi",
lat : 45.2879387963343,
lon : -122.697361707687
}
}
}
}
}'

QueryParsingException[[index] field [lon] is not a geo_point field]

the problem is I have no idea on what the right way to do the mapping is. Unless its dynamic I can't get the mapping override to work, because the docs only give me json snippets. Not a complete mapping file with a full example of a custom mapping.

Please Help!

Regards,
kash.


(kash badami) #2

Also if I try to create a mapping using the api like this:

curl -XPUT 'http://localhost:9200/index/golfcourse/_mapping' -d '
{
"pin" : {
"properties" : {
"location" : {
"properties" : {
"type" : "geo_point"
}
}
}
}
}
'

I get the following exception:

{"error":"ElasticSearchException[java.lang.String cannot be cast to java.util.Map]; nested: ClassCastException[java.lang.String cannot be cast to java.util.Map]; "}dhcp-25-229:elasticsearch

Any help would be greatly appreciated. There is something fundamental I am missing here, if I cant solve this issue, I will have to abandon elastic search for this endeavor and I really believe its the right tool.

Regards,
kash.


(system) #3