Coğrafi sorgular; mesafeye göre coğrafi sorgu, sınırlayıcı kutuya göre coğrafi sorgu ve çokgene göre coğrafi sorgu olmak üzere üç türe ayrılır.
Ön koşullar
Bir OTSClient örneği başlatın. Daha fazla bilgi için bkz. OTSClient örneğini başlatma.
Bir veri tablosu oluşturun ve bu tabloya veri yazın. Daha fazla bilgi için bkz. Veri tabloları oluşturma ve Veri yazma.
Veri tablosu için bir arama dizini oluşturun. Daha fazla bilgi için bkz. Arama dizini oluşturma.
Mesafeye göre coğrafi sorgu
Mesafeye göre coğrafi sorguyu kullanarak bir merkez nokta ve yarıçaptan oluşan dairesel coğrafi alanı sorguda filtreleme koşulu olarak belirtebilirsiniz. Tablestore, Geopoint sütunundaki değeri bu dairesel coğrafi alan içinde kalan satırları döndürür.
-
Parametreler
Parametre
Açıklama
tableName
Veri tablosunun adı.
indexName
Arama dizininin adı.
query
Sorgu türü. Sorgu türünü TableStore.QueryType.GEO_DISTANCE_QUERY olarak ayarlayın.
fieldName
Alanın adı. Alan değerlerinin türü Geopoint'tir.
centerPointMerkez noktanın koordinat çifti. Koordinat çifti enlem ve boylam değerlerinden oluşur.
Bu parametre değeri "enlem,boylam" biçiminde olmalıdır. Enlem için geçerli değerler: [-90,90]. Boylam için geçerli değerler: [-180.180]. Örnek: “35,8,-45,91".
distance
Dairesel coğrafi alanın yarıçapı. Bu parametrenin değeri DOUBLE veri türündedir. Birim: metre. -
Örnekler
Aşağıdaki örnek kod, Col_GeoPoint sütunundaki değerin belirli bir dairesel coğrafi alan içinde kaldığı satırları nasıl sorgulayacağınızı gösterir.
client.search({ tableName: TABLE_NAME, indexName: INDEX_NAME, searchQuery: { offset: 0, limit: 10, // To query only the number of rows that meet the query conditions without specific data, set the limit parameter to 0. query: { // Set the query type to TableStore.QueryType.GEO_DISTANCE_QUERY. queryType: TableStore.QueryType.GEO_DISTANCE_QUERY, query: { fieldName: "Col_GeoPoint", centerPoint: "1.1", // Specify the coordinate pair for the central point. distance: 10000 // Set the distance from the central point to a value smaller than or equal to 10,000. Unit: meter. } }, getTotalCount: true // Specify whether to return the total number of rows that meet the query conditions. Default value: false. }, columnToGet: { // Specify the columns that you want to return. You can set the parameter to RETURN_SPECIFIED to return the specified columns, RETURN_ALL to return all columns, RETURN_ALL_FROM_INDEX to return all columns in the search index, or RETURN_NONE to return only the primary key columns. returnType: TableStore.ColumnReturnType.RETURN_ALL } }, function (err, data) { if (err) { console.log('error:', err); return; } console.log('success:', JSON.stringify(data, null, 2)); });
Sınırlayıcı kutuya göre coğrafi sorgu
Sınırlayıcı kutuya göre coğrafi sorguyu kullanarak dikdörtgen bir coğrafi alanı sorguda filtreleme koşulu olarak belirtebilirsiniz. Tablestore, Geopoint sütunundaki değerin bu dikdörtgen coğrafi alan içinde kaldığı satırları döndürür.
-
Parametreler
Parametre
Açıklama
tableName
Veri tablosunun adı.
indexName
Arama dizininin adı.
query
Sorgu türü. Sorgu türünü TableStore.QueryType.GEO_BOUNDING_BOX_QUERY olarak ayarlayın.
fieldName
Alanın adı. Alan değerlerinin türü Geopoint'tir.
topLeft
Dikdörtgen coğrafi alanın sol üst köşesinin koordinat çifti.
bottomRightDikdörtgen coğrafi alanın sağ alt köşesinin koordinat çifti. Sol üst ve sağ alt köşelerin koordinat çiftleri benzersiz bir dikdörtgen coğrafi alan tanımlar.
Bu parametre değeri "enlem,boylam" biçiminde olmalıdır. Enlem için geçerli değerler: [-90,90]. Boylam için geçerli değerler: [-180.180]. Örnek: “35,8,-45,91".
-
Örnekler
Aşağıdaki örnek kod, sol üst köşe koordinat çifti "10,0" ve sağ alt köşe koordinat çifti "0,10" olan dikdörtgen bir coğrafi alan içinde Col_GeoPoint sütunundaki değerin kaldığı satırları nasıl sorgulayacağınızı gösterir:
client.search({ tableName: TABLE_NAME, indexName: INDEX_NAME, searchQuery: { offset: 0, limit: 10, // To query only the number of rows that meet the query conditions without specific data, set the limit parameter to 0. query: { // Set the query type to TableStore.QueryType.GEO_BOUNDING_BOX_QUERY. queryType: TableStore.QueryType.GEO_BOUNDING_BOX_QUERY, query: { fieldName: "Col_GeoPoint", // Specify the name of the field. topLeft: "10.0", // Specify the coordinate pair for the upper-left corner of the rectangular geographical area. bottomRight: "0.10" // Specify coordinate pair for the lower-right corner of the rectangular geographical area. } }, getTotalCount: true // Specify whether to return the total number of rows that meet the query conditions. Default value: false. }, columnToGet: { // Specify the columns that you want to return. You can set the parameter to RETURN_SPECIFIED to return the specified columns, RETURN_ALL to return all columns, RETURN_ALL_FROM_INDEX to return all columns in the search index, or RETURN_NONE to return only the primary key columns. returnType: TableStore.ColumnReturnType.RETURN_ALL } }, function (err, data) { if (err) { console.log('error:', err); return; } console.log('success:', JSON.stringify(data, null, 2)); });
Çokgene göre coğrafi sorgu
Çokgene göre coğrafi sorguyu kullanarak bir çokgen coğrafi alan belirtebilirsiniz. Tablestore, Geopoint sütunundaki değerin bu çokgen coğrafi alan içinde kalan satırları döndürür.
-
Parametreler
Parametre
Açıklama
tableName
Veri tablosunun adı.
indexName
Arama dizininin adı.
query
Sorgu türü. Sorgu türünü TableStore.QueryType.GEO_POLYGON_QUERY olarak ayarlayın.
fieldName
Alanın adı. Alan değerlerinin türü Geopoint'tir.
pointsÇokgen coğrafi alanı tanımlayan noktaların koordinat çiftleri.
Her noktanın koordinat çifti "enlem,boylam" biçiminde olmalıdır. Enlem için geçerli değerler: [-90,90]. Boylam için geçerli değerler: [-180.180]. Örnek: “35,8,-45,91".
-
Örnekler
Aşağıdaki örnek kod, Col_GeoPoint sütunundaki değerin bir çokgen coğrafi alan içinde kaldığı satırları nasıl sorgulayacağınızı gösterir:
client.search({ tableName: TABLE_NAME, indexName: INDEX_NAME, searchQuery: { offset: 0, limit: 10, // To query only the number of rows that meet the query conditions without specific data, set the limit parameter to 0. query: { // Set the query type to TableStore.QueryType.GEO_POLYGON_QUERY. queryType: TableStore.QueryType.GEO_POLYGON_QUERY, query: { fieldName: "Col_GeoPoint", points: ["0,0","5,5","5,0"] // Specify coordinate pairs for vertices of a polygon geographical area. } }, getTotalCount: true // Specify whether to return the total number of rows that meet the query conditions. Default value: false. }, columnToGet: { // Specify the columns that you want to return. You can set the parameter to RETURN_SPECIFIED to return the specified columns, RETURN_ALL to return all columns, RETURN_ALL_FROM_INDEX to return all columns in the search index, or RETURN_NONE to return only the primary key columns. returnType: TableStore.ColumnReturnType.RETURN_ALL } }, function (err, data) { if (err) { console.log('error:', err); return; } console.log('success:', JSON.stringify(data, null, 2)); });
SSS
İlgili Başlıklar
-
Arama dizinleri aşağıdaki sorgu türlerini destekler: terim sorgusu, terimler sorgusu, tümünü eşleştir sorgusu, eşleştirme sorgusu, ifade eşleştirme sorgusu, önek sorgusu, aralık sorgusu, joker karakterli sorgu, Boolean sorgusu, coğrafi sorgu, iç içe geçmiş sorgu, vektör sorgusu ve varlık sorgusu. İş gereksinimlerinize göre uygun bir sorgu türü seçerek veri sorgulayabilirsiniz.
Sorgu koşullarını karşılayan satırları sıralamak veya sayfalamak istiyorsanız sıralama ve sayfalama özelliğini kullanabilirsiniz. Daha fazla bilgi için bkz. Sıralama ve sayfalama.
Sonuç kümesini belirli bir sütuna göre daraltmak istiyorsanız daraltma (ayrı) özelliğini kullanabilirsiniz. Bu sayede belirtilen türdeki veriler sorgu sonuçlarında yalnızca bir kez görünür. Daha fazla bilgi için bkz. Daraltma (ayrı).
Veri tablosundaki verileri analiz etmek, örneğin uç değerleri, toplamı ve toplam satır sayısını elde etmek istiyorsanız toplama işlemleri yapabilir veya SQL deyimleri çalıştırabilirsiniz. Daha fazla bilgi için bkz. Toplama ve SQL sorgusu.
Satırları sıralama ihtiyacı olmadan sorgu koşullarını karşılayan tüm satırları hızlıca elde etmek istiyorsanız paralel tarama özelliğini kullanmak üzere ParallelScan ve ComputeSplits işlemlerini çağırabilirsiniz. Daha fazla bilgi için bkz. Paralel tarama.