11. Geo Shape

The geo_shape data type facilitates the indexing of and searching with arbitrary geo shapes such as rectangles and polygons. It should be used when either the data being indexed or the queries being executed contain shapes other than just points.

Firstly you have to set index mappings for geo_shape if you haven’t set:

 1<?php
 2
 3
 4$index = $elastic
 5                ->index()
 6                ->name('my-index')
 7                ->mappings(function(){
 8                        return $this
 9                                ->body([
10                                    'properties' => [
11                                        'location' => [
12                                            'type' => 'geo_shape',
13                                        ]
14                                    ]
15                                ])
16                                ->getMap();
17                })
18                ->updateMap();

Save a document to search it

 1<?php
 2
 3$index = $elastic->document()
 4                ->index('my-index')
 5                ->body([
 6                    'text' => 'Şêro',
 7                    'location' => [
 8                        'type' => 'point',
 9                        'coordinates' => [-77.30, 38.34],
10                    ]
11                ])
12                ->save();

Lets do a CIRCLE example:

 1<?php
 2
 3$geo = $elastic->geoShape()
 4                ->index('my-index')
 5                ->type('circle')
 6                ->text('Şêro')
 7                ->coordinates([-77.30, 38.34])
 8                ->radius('111km')
 9                ->search();
10
11return $geo;

For more information: https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-shape.html