I tried a spatial search with Amazon OpenSearch Service and visualized it with QGIS 🎉
The following is a detailed explanation.
- Advance Preparation
- Create a domain
- Connect to OpenSearch Dashboards
- Register location data
- Spatial Search
Advance Preparation
Prepare GIS data for use with Amazon OpenSearch Service. This time, I prepared a sample of OpenStreetMap data in QGIS in advance.
I prepared GIS data of points in GeoJSON and then pre-modified GeoJSON to JSON for import.
I have registered this sample data on GitHub, so please feel free to use it.
https://github.com/dayjournal/data/tree/main/try-092
Now you're all set with your preliminary GIS data!
Creating a domain
This is how to create a domain in Amazon OpenSearch Service.
Click AWS Management Console → Amazon OpenSearch Service.
Set the domain name, deployment type, and autotuning.
Set up a data node and dedicated master node.
Configure network, fine-grained access control, and access policy.
Enter user name and password to create user.
The network was set up with public access for this demonstration.
Set encryption → Click "Create".
Wait a few moments and the environment construction will be completed.
You have now completed the creation of your domain!
Connect to OpenSearch Dashboards
This is how to connect to OpenSearch Dashboards with Amazon OpenSearch Service.
Click on the OpenSearch Dashboards URL.
Enter the username and password you set when creating the domain → Click "Log In".
You will be connected to OpenSearch Dashboards.
You are now connected to OpenSearch Dashboards!
Location data registration
This is how to register location data with Amazon OpenSearch Service.
Connect to OpenSearch Dashboards → Click on "Dev Tools".
Set the index for location data. In this case, we used "geo_shape".
PUT point_geo_sample
{
"mappings": {
"properties": {
"geometry": {
"type": "geo_shape"
}
}
}
}
Import location data. The original GeoJSON data is pre-modified to JSON for import.
POST point_geo_sample/_bulk
{"index": {}}
{ "type": "Feature", "properties": { "full_id": "n260423690", "name": "文教堂書店", "shop": "books" }, "geometry": { "type": "Point", "coordinates": [ 139.7577071, 35.6678306 ] } }
{"index": {}}
{ "type": "Feature", "properties": { "full_id": "n260424181", "name": "LABI", "shop": "electric" }, "geometry": { "type": "Point", "coordinates": [ 139.757034800000014, 35.6671262 ] } }
{"index": {}}
{ "type": "Feature", "properties": { "full_id": "n260424208", "name": "キムラヤ", "shop": "electric" }, "geometry": { "type": "Point", "coordinates": [ 139.7577643, 35.665613 ] } }
{"index": {}}
{ "type": "Feature", "properties": { "full_id": "n261024380", "name": "ソフトバンクショップ", "shop": "mobile_phone" }, "geometry": { "type": "Point", "coordinates": [ 139.7773429, 35.6772184 ] } }
{"index": {}}
{ "type": "Feature", "properties": { "full_id": "n410500414", "name": "ミニストップ", "shop": "convenience" }, "geometry": { "type": "Point", "coordinates": [ 139.745115, 35.7081941 ] } }
{"index": {}}
{ "type": "Feature", "properties": { "full_id": "n417434047", "name": "Inplexe", "shop": "accessories" }, "geometry": { "type": "Point", "coordinates": [ 139.7414085, 35.7005685 ] } }
{"index": {}}
{ "type": "Feature", "properties": { "full_id": "n439115834", "name": "フォルクスワーゲン六本木", "shop": "car" }, "geometry": { "type": "Point", "coordinates": [ 139.7359042, 35.665522 ] } }
{"index": {}}
{ "type": "Feature", "properties": { "full_id": "n474605269", "name": "Family Mart", "shop": "convenience" }, "geometry": { "type": "Point", "coordinates": [ 139.7499649, 35.6692143 ] } }
{"index": {}}
{ "type": "Feature", "properties": { "full_id": "n474605283", "name": "セブン-イレブン", "shop": "convenience" }, "geometry": { "type": "Point", "coordinates": [ 139.7540003, 35.668082 ] } }
{"index": {}}
{ "type": "Feature", "properties": { "full_id": "n474605289", "name": "Lawson", "shop": "convenience" }, "geometry": { "type": "Point", "coordinates": [ 139.754741599999988, 35.6676069 ] } }
{"index": {}}
{ "type": "Feature", "properties": { "full_id": "n559359769", "name": "LAWSON 銀座6丁目店", "shop": "convenience" }, "geometry": { "type": "Point", "coordinates": [ 139.7657173, 35.6687584 ] } }
{"index": {}}
....
This completes the registration of location data!
Spatial Search
Finally, we will show you how to perform a spatial search with Amazon OpenSearch Service.
For this spatial search, we will search for point data in the bbox as shown below. In advance, visualize the data in QGIS and prepare the latitude and longitude of the upper left and lower right points you want to search.
Specify the conditions for spatial search and enter the latitude and longitude of the upper left and lower right.
POST point_geo_sample/_search
{
"query":{
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_shape": {
"geometry": {
"shape": {
"type": "envelope",
"coordinates" : [[139.7802, 35.6781], [139.7878, 35.6724]]
},
"relation": "within"
}
}
}
}
}
}
The search results matched the QGIS visualization!
{
"took" : 9,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "point_geo_sample",
"_type" : "_doc",
"_id" : "mdQ_54EBMGUV534vZahT",
"_score" : 1.0,
"_source" : {
"type" : "Feature",
"properties" : {
"full_id" : "n1892534950",
"name" : "セブン-イレブン",
"shop" : "convenience"
},
"geometry" : {
"type" : "Point",
"coordinates" : [
139.7819038,
35.675297
]
}
}
},
{
"_index" : "point_geo_sample",
"_type" : "_doc",
"_id" : "yNQ_54EBMGUV534vZa1Z",
"_score" : 1.0,
"_source" : {
"type" : "Feature",
"properties" : {
"full_id" : "n3758524951",
"name" : "セブン-イレブン",
"shop" : "convenience"
},
"geometry" : {
"type" : "Point",
"coordinates" : [
139.7859394,
35.6769875
]
}
}
},
{
"_index" : "point_geo_sample",
"_type" : "_doc",
"_id" : "KtQ_54EBMGUV534vZadN",
"_score" : 1.0,
"_source" : {
"type" : "Feature",
"properties" : {
"full_id" : "n1215847202",
"name" : "NATURAL LAWSON",
"shop" : "convenience"
},
"geometry" : {
"type" : "Point",
"coordinates" : [
139.781879,
35.6744447
]
}
}
}
]
}
}
By using the Amazon OpenSearch Service, you can search the imported data spatially!
Related Articles
Spatial Search of Amazon S3 Data with Amazon Athena and Visualized It in QGIS
Yasunori Kirimoto for AWS Community Builders ・ May 16 '22
Spatial Search with Amazon Redshift and DBeaver
Yasunori Kirimoto for AWS Community Builders ・ Dec 3 '21
Using QGIS and Amazon Aurora PostgreSQL & PostGIS to Display Location Data
Yasunori Kirimoto for AWS Community Builders ・ Nov 3 '21
References
Amazon OpenSearch Service
QGIS
Top comments (0)