설정
elasticsearch geo-shape 쿼리 조회
한만큼
2019. 11. 20. 10:08
"boundaries":{
"type": "geo_shape",
"ignore_malformed": true,
"precision": "1.0m",
"strategy": "recursive",
"distance_error_pct": 0.009
},
bounboundaries 는 geo_shape 타입 필드이구, 이렇게 해줘야 document들이 정상적으로 조회된다.
첨에 이 필드를 text로 만들었다가, documents들을 json으로 교체하려고하니까 변경이 되지 않았다.
해결방법 )
1 reindex하여
PUT https://엘라스틱서치호스트/생성하고자하는_호스트명
2 먼저 매핑타입을 설정해준뒤
PUT https://엘라스틱서치호스트/인덱스이름/_mapping/doc
Content-Type: application/json
{
"properties": {
"boundaries": {
"type": "geo_shape",
"precision": "1.0m",
"strategy": "recursive",
"distance_error_pct": 0.009,
"ignore_malformed": "true"
}
}
}
3 document들을 배치작업으로 create했다.
4 결과 확인
(조회 쿼리)
POST https://엘라스틱서치_호스트/해당_인덱스이름/_search
{
"query":{
"bool":{
"filter":{
"geo_shape":{
"boundaries":{
"shape":{
"type":"Point",
"coordinates":[3.342369,45.527378]
},
"relation": "contains"
}
}
}
}
},
"sort":[
{
"region_level":"asc"
}
]
}
(결과)
{
"took": 4,
"timed_out": false,
"_shards":{
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits":{
"total": 2,
"max_score": null,
"hits":[
{
"_index": "expedia_migrated_20191119_3",
"_type": "doc",
"_id": "3000442158",
"_score": null,
"_source":{
"region_type": "city",
"region_code": "3000442158",
"region_name": "Usson",
"region_level": 5,
"center_longitude": "3.342369",
"center_latitude": "45.527378",
"parent":{"id": "6053052", "type": "province_state"},
"continent":{"code": "6022967", "name": "Europe"},
"country":{"code": "59", "name": "France", "country_code": "FR"},
"province_b":{"id": "6053052", "type": "province_state"},
"province":{"id": "6049830", "type": "province_state"},
"multicity":[],
"codes":{},
"boundaries":{
"type": "Polygon",
"coordinates":[[[3.326324, 45.519959 ], [3.326385,…}
},
"sort":[
5
]