Gabatarwa zuwa Neman Gelocation in Elasticsearch

Da farko, kuna buƙatar shigarwa Elasticsearch akan sabar ku ko amfani da sabis na tushen girgije Elasticsearch kamar Elastic Cloud. Tabbatar kun shigar da sigar da ta dace Elasticsearch tare da kayan aikin GeoPoint.

 

Shigar kuma Sanya GeoPoint Plugin

Elasticsearch yana goyan bayan binciken geolocation ta hanyar kayan aikin GeoPoint. Don shigar da wannan plugin ɗin, zaku iya amfani da Elasticsearch kayan aikin sarrafa kayan aikin plugin.

Misali, idan kuna amfani da Elasticsearch sigar 7.x, zaku iya gudanar da umarni mai zuwa don shigar da kayan aikin GeoPoint:

bin/elasticsearch-plugin install ingest-geoip

Bayan shigar da kayan aikin GeoPoint, kuna buƙatar saita fihirisar ku don amfani da nau'in bayanan "geo_point" don filin da zai riƙe bayanan geolocation. Don yin wannan, zaku iya ko dai shirya taswirar fihirisar data kasance ko ƙirƙiri sabon fihirisa tare da saita taswira.

 

Ƙayyade Filin Wurin Ƙasa a Taswira

Ƙara filin yanki zuwa fihirisar ku kuma shirya taswirar wannan filin. Filin geolocation yawanci yana amfani da nau'in bayanan "geo_point". Taswirar za ta ayyana halaye da zaɓuɓɓuka don filin yanki, kamar daidaitattun daidaitawa, tsari, da ƙari.

Misali:

PUT /my_locations_index  
{  
  "mappings": {  
    "properties": {  
      "location": {  
        "type": "geo_point"  
      }  
    }  
  }  
}  

 

Gyara Bayanai

Ƙara bayanin wuri zuwa takaddun ku. Yawanci, bayanin wurin wuri ana wakilta azaman biyu longitude da latitude masu daidaitawa. Kuna iya samun wannan bayanin daga masu amfani ta amfani da Google Maps API ko wasu tushen bayanan ƙasa.

Misali:

PUT /my_locations_index/_doc/1  
{  
  "name": "Ba Dinh Square",  
  "location": {  
    "lat": 21.03405,  
    "lon": 105.81507  
  }  
}  

 

Yi Neman Gelocation

Yanzu da kuna da bayanan yanki a cikin Elasticsearch fihirisar ku, zaku iya yin tambayoyin neman wuri don nemo takardu kusa da takamaiman wuri ko tsakanin wani yanki na yanki. Don yin binciken yanayin ƙasa, zaku iya amfani da Elasticsearch tambayoyin madaidaitan kamar geo_distance, geo_bounding_box, geo_polygon, da sauransu.

Misali: Nemo wurare kusa da masu daidaitawa(21.03405, 105.81507) tsakanin radius 5km.

GET /my_locations_index/_search  
{  
  "query": {  
    "geo_distance": {  
      "distance": "5km",  
      "location": {  
        "lat": 21.03405,  
        "lon": 105.81507  
      }  
    }  
  }  
}  

 

Haɗa Google Maps

Idan kuna son haɗawa Google Maps tare da Elasticsearch don samun bayanan yanki daga masu amfani, zaku iya amfani da Google Maps API don dawo da haɗin kan layi da latitude dangane da adireshi ko wurin da masu amfani suka zaɓa. Sa'an nan, za ka iya amfani da wannan bayanin don ƙara bayanan wuri a cikin Elasticsearch fihirisar ku da kuma yin tambayoyin neman wuri.

A ƙarshe, haɗawa Google Maps tare da Elasticsearch yana ba ku damar yin amfani da fasalulluka na binciken ƙasa a cikin bayanan ku, yana ba da damar ingantaccen bincike mai inganci dangane da bayanan ƙasa.