geoShape
정의
geoShape
인덱스 정의에서
indexShapes
이true
로 설정된 경우geoShape
연산자는 지정된 도형과의 관계가 있는 도형 쿼리를 지원합니다.검색할 좌표를 지정할 때는 경도를 먼저 지정한 다음 위도를 지정해야 합니다. 경도 값 범위는
-180
~180
사이이며 둘 다 포함합니다. 위도 값 범위는-90
~90
이며 둘 다 포함합니다. 좌표 값은 정수 또는 이중 값일 수 있습니다.참고
Atlas Search에서는 다음을 지원하지 않습니다.
기본값이 좌표 기준계(CRS)
평면형 XY 좌표계(2차원)
좌표 쌍 점 표기법(즉,
pointFieldName: [12, 34]
)
구문
1 { 2 "$search": { 3 "index": <index name>, // optional, defaults to "default" 4 "geoShape": { 5 "path": "<field-to-search>", 6 "relation": "contains | disjoint | intersects | within", 7 "geometry": <GeoJSON-object>, 8 "score": <score-options> 9 } 10 } 11 }
옵션
geoShape
은(는) 다음 텀은 사용하여 쿼리를 구성합니다.
필드 | 유형 | 설명 | 필요성 |
---|---|---|---|
| GeoJSON 객체 | 다각형 , 다중 다각형 또는GeoJSON라인스트링 모양 또는 지점을 지정하는 객체로, Atlas Search를 가리킵니다. 다각형은 마지막 위치가 첫 번째 위치와 동일한 닫힌 루프로 지정되어야 합니다. 지리 공간적 결과를 계산할 때 Atlas Search geoShape 및 geoWithin 연산자와 MongoDB $geoIntersects 연산자 서로 다른 도형을 사용합니다. 이 차이는 Atlas Search 와 MongoDB 다각형 가장자리를 그리는 방식에서 확인할 수 있습니다. Atlas Search는 좌표계서 두 점 사이의 가장 짧은 선인 유클리드 거리를 기준으로 다각형을 그립니다. MongoDB 측지 유형용 타사 라이브러리를 기반으로 하는 2dsphere 인덱스를 기반으로 하는 측지 모드 또는 2d 인덱스의 플랫 모드 사용하여 다각형을 그립니다. 자세한 학습 GeoJSON 객체를 참조하세요. Atlas Search와 MongoDB는 다각형과 관련된 지리 공간적 쿼리에 대해 서로 다른 결과를 반환할 수 있습니다. | 네 |
| 문자열 또는 문자열 배열 | 네 | |
| 열거형 | 쿼리 형태 도형과 인덱싱된 필드 도형의 관계입니다. 값은 다음 중 하나일 수 있습니다.
| 네 |
| 객체 | 일치하는 검색 결과에 할당할 점수입니다. 기본적으로 결과의 점수 는
쿼리에서 | no |
예시
다음 예제에서는 sample_airbnb
데이터베이스의 listingsAndReviews
컬렉션을 사용합니다. 클러스터에 샘플 데이터 세트 가 있는 경우 지리적 유형에 대한 사용자 지정 Atlas Search 인덱스를 만들고 클러스터에서 예제 쿼리를 실행할 수 있습니다.
팁
샘플 데이터 집합을 이미 로드한 경우, Atlas Search 시작하기 자습서에 따라 인덱스 정의를 만들고 Atlas Search 쿼리를 실행하세요.
다음은 listingsAndReviews
collection의 address.location
필드를 인덱싱하기 위한 샘플 인덱스 정의입니다.
1 { 2 "mappings": { 3 "fields": { 4 "address": { 5 "fields": { 6 "location": { 7 "indexShapes": true, 8 "type": "geo" 9 } 10 }, 11 "type": "document" 12 } 13 } 14 } 15 }
Atlas Search 시작하기에는 샘플 데이터 세트 로드, 인덱스 정의 생성 및 Atlas Search 검색 쿼리 실행에 대한 지침이 포함되어 있습니다.
참고
다음 샘플 쿼리의 경우 인덱스 정의에서 indexShapes
가 true
로 설정되어 있는지 확인합니다.
분리된 예제
다음 예에서는 geoShape
연산자를 사용하여 하와이의 지정된 경도 및 위도 좌표와 공통점이 없는 속성을 검색합니다.
쿼리에는 다음이 포함됩니다.
1 db.listingsAndReviews.aggregate([ 2 { 3 "$search": { 4 "geoShape": { 5 "relation": "disjoint", 6 "geometry": { 7 "type": "Polygon", 8 "coordinates": [[[-161.323242,22.512557], 9 [-152.446289,22.065278], 10 [-156.09375,17.811456], 11 [-161.323242,22.512557]]] 12 }, 13 "path": "address.location" 14 } 15 } 16 }, 17 { 18 $limit: 3 19 }, 20 { 21 $project: { 22 "_id": 0, 23 "name": 1, 24 "address": 1, 25 score: { $meta: "searchScore" } 26 } 27 } 28 ])
쿼리는 다음과 같은 검색 결과를 반환합니다.
1 { 2 "name" : "Ribeira Charming Duplex", 3 "address" : { 4 "street" : "Porto, Porto, Portugal", 5 "suburb" : "", 6 "government_area" : "Cedofeita, Ildefonso, Sé, Miragaia, Nicolau, Vitória", 7 "market" : "Porto", 8 "country" : "Portugal", 9 "country_code" : "PT", 10 "location" : { 11 "type" : "Point", 12 "coordinates" : [ -8.61308, 41.1413 ], 13 "is_location_exact" : false 14 } 15 } 16 } 17 { 18 "name" : "Horto flat with small garden", 19 "address" : { 20 "street" : "Rio de Janeiro, Rio de Janeiro, Brazil", 21 "suburb" : "Jardim Botânico", 22 "government_area" : "Jardim Botânico", 23 "market" : "Rio De Janeiro", 24 "country" : "Brazil", 25 "country_code" : "BR", 26 "location" : { 27 "type" : "Point", 28 "coordinates" : [ -43.23074991429229, -22.966253551739655 ], 29 "is_location_exact" : true 30 } 31 } 32 } 33 { 34 "name" : "Private Room in Bushwick", 35 "address" : { 36 "street" : "Brooklyn, NY, United States", 37 "suburb" : "Brooklyn", 38 "government_area" : "Bushwick", 39 "market" : "New York", 40 "country" : "United States", 41 "country_code" : "US", 42 "location" : { 43 "type" : "Point", 44 "coordinates" : [ -73.93615, 40.69791 ], 45 "is_location_exact" : true 46 } 47 } 48 }
교차 예제
다음 예제에서는 geoShape
연산자를 사용하여 스페인에서 지정된 경도 및 위도 좌표와 교차하는 속성을 검색합니다.
쿼리에는 다음이 포함됩니다.
1 db.listingsAndReviews.aggregate([ 2 { 3 "$search": { 4 "geoShape": { 5 "relation": "intersects", 6 "geometry": { 7 "type": "MultiPolygon", 8 "coordinates": [ 9 [[[2.16942,41.40082], 10 [2.17963,41.40087], 11 [2.18146,41.39716], 12 [2.15533,41.40686], 13 [2.14596,41.38475], 14 [2.17519,41.41035], 15 [2.16942,41.40082]]], 16 [[[2.16365,41.39416], 17 [2.16963,41.39726], 18 [2.15395,41.38005], 19 [2.17935,41.43038], 20 [2.16365,41.39416]]] 21 ] 22 }, 23 "path": "address.location" 24 } 25 } 26 }, 27 { 28 $limit: 3 29 }, 30 { 31 $project: { 32 "_id": 0, 33 "name": 1, 34 "address": 1, 35 score: { $meta: "searchScore" } 36 } 37 } 38 ])
쿼리는 다음과 같은 검색 결과를 반환합니다.
1 { 2 "name" : "Cozy bedroom Sagrada Familia", 3 "address" : { 4 "street" : "Barcelona, Catalunya, Spain", 5 "suburb" : "Eixample", 6 "government_area" : "el Fort Pienc", 7 "market" : "Barcelona", 8 "country" : "Spain", 9 "country_code" : "ES", 10 "location" : { 11 "type" : "Point", 12 "coordinates" : [ 2.17963, 41.40087 ], 13 "is_location_exact" : true 14 } 15 } 16 } 17 { 18 "name" : "", 19 "address" : { 20 "street" : "Barcelona, Catalunya, Spain", 21 "suburb" : "Vila de Gràcia", 22 "government_area" : "la Vila de Gràcia", 23 "market" : "Barcelona", 24 "country" : "Spain", 25 "country_code" : "ES", 26 "location" : { 27 "type" : "Point", 28 "coordinates" : [ 2.15759, 41.40349 ], 29 "is_location_exact" : true 30 } 31 } 32 } 33 { 34 "name" : "SPACIOUS RAMBLA CATALUÑA", 35 "address" : { 36 "street" : "Barcelona, Catalunya, Spain", 37 "suburb" : "L'Antiga Esquerra de l'Eixample", 38 "government_area" : "l'Antiga Esquerra de l'Eixample", 39 "market" : "Barcelona", 40 "country" : "Spain", 41 "country_code" : "ES", 42 "location" : { 43 "type" : "Point", 44 "coordinates" : [ 2.15255, 41.39193 ], 45 "is_location_exact" : true 46 } 47 } 48 }
예제 내
다음 예제에서는 geoShape
연산자를 사용하여 지정된 경도 및 위도 좌표 내에 있는 뉴욕의 속성을 검색합니다. 쿼리는 sample_airbnb
데이터베이스의 listingsAndReviews
collection에 있는 address.location
필드를 검색합니다.
쿼리에는 다음이 포함됩니다.
1 db.listingsAndReviews.aggregate([ 2 { 3 "$search": { 4 "geoShape": { 5 "relation": "within", 6 "geometry": { 7 "type": "Polygon", 8 "coordinates": [[[-74.3994140625,40.5305017757], 9 [-74.7290039063,40.5805846641], 10 [-74.7729492188,40.9467136651], 11 [-74.0698242188,41.1290213475], 12 [-73.65234375,40.9964840144], 13 [-72.6416015625,40.9467136651], 14 [-72.3559570313,40.7971774152], 15 [-74.3994140625,40.5305017757]]] 16 }, 17 "path": "address.location" 18 } 19 } 20 }, 21 { 22 $limit: 3 23 }, 24 { 25 $project: { 26 "_id": 0, 27 "name": 1, 28 "address": 1, 29 score: { $meta: "searchScore" } 30 } 31 } 32 ])
쿼리는 다음과 같은 검색 결과를 반환합니다.
1 { 2 "name" : "Private Room in Bushwick", 3 "address" : { 4 "street" : "Brooklyn, NY, United States", 5 "suburb" : "Brooklyn", 6 "government_area" : "Bushwick", 7 "market" : "New York", 8 "country" : "United States", 9 "country_code" : "US", 10 "location" : { 11 "type" : "Point", 12 "coordinates" : [ -73.93615, 40.69791 ], 13 "is_location_exact" : true 14 } 15 }, 16 { 17 "name" : "New York City - Upper West Side Apt", 18 "address" : { 19 "street" : "New York, NY, United States", 20 "suburb" : "Manhattan", 21 "government_area" : "Upper West Side", 22 "market" : "New York", 23 "country" : "United States", 24 "country_code" : "US", 25 "location" : { 26 "type" : "Point", 27 "coordinates" : [ -73.96523, 40.79962 ], 28 "is_location_exact" : false 29 } 30 }, 31 "score" : 1 32 } 33 { 34 "name" : "Deluxe Loft Suite", 35 "address" : { 36 "street" : "Brooklyn, NY, United States", 37 "suburb" : "Greenpoint", 38 "government_area" : "Greenpoint", 39 "market" : "New York", 40 "country" : "United States", 41 "country_code" : "US", 42 "location" : { 43 "type" : "Point", 44 "coordinates" : [ -73.94472, 40.72778 ], 45 "is_location_exact" : true 46 } 47 }, 48 "score" : 1 49 }