lundi 27 juin 2016

Creating json_array objects with Elasticsearch-PHP

I am trying to index where the field i have mapped requires an object.

According to: https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_dealing_with_json_arrays_and_objects_in_php.html

    $params['body'] = [

            'location' => new stdClass()

    ];

should have been sufficient to indicate an empty PHP Object, but it fails on the miss match stating that location is an object mapping and It is wrong.

I have tried the following also:

    $params['body'] = [

            'location' => new stdClass(['lat'=>0,'lon'=>0])

    ];

But that failed with the same reason.

However if I do a raw curl api to elasticsearch:

curl -XPOST 'http://localhost:9200/my_index/my_type/1' -d '{"location":{"lat":0.0,"lon":0.0}}'

this works.

Aucun commentaire:

Enregistrer un commentaire