axel wolf
axel wolf

Reputation: 1478

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.)

Upvotes: 4

Views: 4082

Answers (2)

villasv
villasv

Reputation: 6861

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.

Upvotes: 5

axel wolf
axel wolf

Reputation: 1478

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.

Upvotes: 0

Related Questions