简体   繁体   中英

elasticsearch mapping of geo_point with null_value

I ran into an issue related to elasticsearch's geo_point while importing from a DB. My mapping works great if value for lon or lat field contains real values.

Now it can happen that some rows contain empty values for lon/lat and if I try to import these I get a ElasticsearchParseException[latitude must be a number] error which totaly seems legit.

So I want to set these fields to 0,0 or NULL,NULL but this is where I get stuck.

I tried to add 'null_value' => '0' to the mapping but that doesn't seem to work.

This is how the mapping looks like:

'_source' => array(
            'enabled' => true
        ),
        'properties' => array(
            'coordinates' => array(
                'type' => 'geo_point',
                'null_value' => '0'
            )
        )

Anyone aware of this?

(I am using the PHP Elasticsearch Client.)

FWIW this is an issue with your document structure, not the presence of null values.

If you have a field coordinates with mapping type geo_point , you must insert your document with {..., coordinates: null} instead of {..., coordinates: {lat: null, lon: null}} or similar equivalent formats . The entire field must be missing, not its inner data.

Found a solution that is fine for me but doesn't solve the actual problem.

In my DB query I convert null to 0 using COALESCE in Posgresql which is similar to IFNULL in mysql.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM