@@ -35,32 +35,32 @@ reference page for a full description of both types.
3535The following command creates a ` GEO ` index for JSON objects that contain
3636the geospatial data in a field called ` location ` :
3737
38- ``` bash
38+ {{< clients-example geoindex create_geo_idx >}}
3939> FT.CREATE productidx ON JSON PREFIX 1 product: SCHEMA $.location AS location GEO
4040 OK
41- ```
41+ {{< /clients-example >}}
4242
4343If you now add JSON objects with the ` product: ` prefix and a ` location ` field,
4444they will be added to the index automatically:
4545
46- ``` bash
46+ {{< clients-example geoindex add_geo_json >}}
4747> JSON.SET product:46885 $ '{"description": "Navy Blue Slippers","price": 45.99,"city": "Denver","location": "-104.991531, 39.742043"}'
4848 OK
4949> JSON.SET product:46886 $ '{"description": "Bright Green Socks","price": 25.50,"city": "Fort Collins","location": "-105.0618814,40.5150098"}'
5050 OK
51- ```
51+ {{< /clients-example >}}
5252
5353The query below finds products within a 100 mile radius of Colorado Springs
5454(Longitude=-104.800644, Latitude=38.846127). This returns only the location in
5555Denver, but a radius of 200 miles would also include the location in Fort Collins:
5656
57- ``` bash
57+ {{< clients-example geoindex geo_query >}}
5858> FT.SEARCH productidx '@location :[ -104.800644 38.846127 100 mi] '
59591 ) "1"
60602 ) "product:46885"
61613 ) 1 ) "$"
6262 2 ) "{\" description\" :\" Navy Blue Slippers\" ,\" price\" :45.99,\" city\" :\" Denver\" ,\" location\" :\" -104.991531, 39.742043\" }"
63- ```
63+ {{< /clients-example >}}
6464
6565See [ Geospatial queries] ({{< relref "/develop/interact/search-and-query/query/geo-spatial" >}})
6666for more information about the available options.
@@ -73,14 +73,14 @@ of the field definition specifies Cartesian coordinates instead of
7373the default spherical geographical coordinates. Use ` SPHERICAL ` in
7474place of ` FLAT ` to choose the coordinate space explicitly.
7575
76- ``` bash
76+ {{< clients-example geoindex create_gshape_idx >}}
7777> FT.CREATE geomidx ON JSON PREFIX 1 shape: SCHEMA $.name AS name TEXT $.geom AS geom GEOSHAPE FLAT
7878 OK
79- ```
79+ {{< /clients-example >}}
8080
8181Use the ` shape: ` prefix for the JSON objects to add them to the index:
8282
83- ``` bash
83+ {{< clients-example geoindex add_gshape_json >}}
8484> JSON.SET shape:1 $ '{"name": "Green Square", "geom": "POLYGON ((1 1, 1 3, 3 3, 3 1, 1 1))"}'
8585 OK
8686> JSON.SET shape:2 $ '{"name": "Red Rectangle", "geom": "POLYGON ((2 2.5, 2 3.5, 3.5 3.5, 3.5 2.5, 2 2.5))"}'
8989 OK
9090> JSON.SET shape:4 $ '{"name": "Purple Point", "geom": "POINT (2 2)"}'
9191 OK
92- ```
92+ {{< /clients-example >}}
9393
9494You can now run various geospatial queries against the index. For
9595example, the query below returns any shapes within the boundary
9696of the green square but omits the green square itself:
9797
98- ``` bash
98+ {{< clients-example geoindex gshape_query >}}
9999> FT.SEARCH geomidx "(-@name :(Green Square) @geom :[ WITHIN $qshape] )" PARAMS 2 qshape "POLYGON ((1 1, 1 3, 3 3, 3 1, 1 1))" RETURN 1 name DIALECT 4
100100
1011011 ) (integer) 1
1021022 ) "shape:4"
1031033 ) 1 ) "name"
104104 2 ) "[ \" Purple Point\" ] "
105- ```
105+ {{< /clients-example >}}
106106
107107You can also run queries to find whether shapes in the index completely contain
108108or overlap each other. See
0 commit comments