@@ -35,32 +35,32 @@ reference page for a full description of both types.
35
35
The following command creates a ` GEO ` index for JSON objects that contain
36
36
the geospatial data in a field called ` location ` :
37
37
38
- ``` bash
38
+ {{< clients-example geoindex create_geo_idx >}}
39
39
> FT.CREATE productidx ON JSON PREFIX 1 product: SCHEMA $.location AS location GEO
40
40
OK
41
- ```
41
+ {{< /clients-example >}}
42
42
43
43
If you now add JSON objects with the ` product: ` prefix and a ` location ` field,
44
44
they will be added to the index automatically:
45
45
46
- ``` bash
46
+ {{< clients-example geoindex add_geo_json >}}
47
47
> JSON.SET product:46885 $ '{"description": "Navy Blue Slippers","price": 45.99,"city": "Denver","location": "-104.991531, 39.742043"}'
48
48
OK
49
49
> JSON.SET product:46886 $ '{"description": "Bright Green Socks","price": 25.50,"city": "Fort Collins","location": "-105.0618814,40.5150098"}'
50
50
OK
51
- ```
51
+ {{< /clients-example >}}
52
52
53
53
The query below finds products within a 100 mile radius of Colorado Springs
54
54
(Longitude=-104.800644, Latitude=38.846127). This returns only the location in
55
55
Denver, but a radius of 200 miles would also include the location in Fort Collins:
56
56
57
- ``` bash
57
+ {{< clients-example geoindex geo_query >}}
58
58
> FT.SEARCH productidx '@location :[ -104.800644 38.846127 100 mi] '
59
59
1 ) "1"
60
60
2 ) "product:46885"
61
61
3 ) 1 ) "$"
62
62
2 ) "{\" description\" :\" Navy Blue Slippers\" ,\" price\" :45.99,\" city\" :\" Denver\" ,\" location\" :\" -104.991531, 39.742043\" }"
63
- ```
63
+ {{< /clients-example >}}
64
64
65
65
See [ Geospatial queries] ({{< relref "/develop/interact/search-and-query/query/geo-spatial" >}})
66
66
for more information about the available options.
@@ -73,14 +73,14 @@ of the field definition specifies Cartesian coordinates instead of
73
73
the default spherical geographical coordinates. Use ` SPHERICAL ` in
74
74
place of ` FLAT ` to choose the coordinate space explicitly.
75
75
76
- ``` bash
76
+ {{< clients-example geoindex create_gshape_idx >}}
77
77
> FT.CREATE geomidx ON JSON PREFIX 1 shape: SCHEMA $.name AS name TEXT $.geom AS geom GEOSHAPE FLAT
78
78
OK
79
- ```
79
+ {{< /clients-example >}}
80
80
81
81
Use the ` shape: ` prefix for the JSON objects to add them to the index:
82
82
83
- ``` bash
83
+ {{< clients-example geoindex add_gshape_json >}}
84
84
> JSON.SET shape:1 $ '{"name": "Green Square", "geom": "POLYGON ((1 1, 1 3, 3 3, 3 1, 1 1))"}'
85
85
OK
86
86
> 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))"}'
89
89
OK
90
90
> JSON.SET shape:4 $ '{"name": "Purple Point", "geom": "POINT (2 2)"}'
91
91
OK
92
- ```
92
+ {{< /clients-example >}}
93
93
94
94
You can now run various geospatial queries against the index. For
95
95
example, the query below returns any shapes within the boundary
96
96
of the green square but omits the green square itself:
97
97
98
- ``` bash
98
+ {{< clients-example geoindex gshape_query >}}
99
99
> 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
100
100
101
101
1 ) (integer) 1
102
102
2 ) "shape:4"
103
103
3 ) 1 ) "name"
104
104
2 ) "[ \" Purple Point\" ] "
105
- ```
105
+ {{< /clients-example >}}
106
106
107
107
You can also run queries to find whether shapes in the index completely contain
108
108
or overlap each other. See
0 commit comments