How can I map an empty string field with the geo-point type?


(Miracle24) #1

Hello, I use the elasticsearch-jdbc to import data from mysql to ES.here is my shell command:
echo ' { "type" : "jdbc", "jdbc" : { "url" : "jdbc:mysql://localhost:3306/test", "user" : "", "password" : "", "locale" : "en_US", "sql" : "select \"world\" as _index, \"city\" as _type, name as _id, city, zip, address, lat as \"location.lat\", lon as \"location.lon\" from geo", "elasticsearch" : { "cluster" : "elasticsearch", "host" : "localhost", "port" : 9300 }, "index" : "world", "type" : "city", "index_settings" : { "index" : { "number_of_shards" : 1 } }, "type_mapping": { "city" : { "properties" : { "location" : { "type" : "geo_point" } } } } } } ' | java \ -cp "${lib}/*" \ -Dlog4j.configurationFile=${bin}/log4j2.xml \ org.xbib.tools.Runner \ org.xbib.tools.JDBCImporter

In mysql database,the field "lat" and "lon" are string type(Don't ask me why), so when I run the above command, I got this:
Caused by: java.lang.NumberFormatException: empty String at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1842) at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110) at java.lang.Double.parseDouble(Double.java:538) at org.elasticsearch.common.xcontent.support.AbstractXContentParser.doubleValue(AbstractXContentParser.java:182) at org.elasticsearch.common.geo.GeoUtils.parseGeoPoint(GeoUtils.java:368) at org.elasticsearch.index.mapper.geo.GeoPointFieldMapper.parse(GeoPointFieldMapper.java:671) at org.elasticsearch.index.mapper.DocumentParser.parseObjectOrField(DocumentParser.java:314) at org.elasticsearch.index.mapper.DocumentParser.parseObject(DocumentParser.java:331) at org.elasticsearch.index.mapper.DocumentParser.parseObject(DocumentParser.java:257) at org.elasticsearch.index.mapper.DocumentParser.innerParseDocument(DocumentParser.java:127)

I know the reason.The data of field "lat" and "lon" is empty in database and when the ES tried to map it with the geo_point type as I required, the exception would happen.
So,how can solve this "empty string field mapping to geo_point type" problem?Can somebody give advice?
Thanks a lot!


(system) #2