Super Kawaii Cute Cat Kaoani
๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Linux

[elasticsearch] kibana๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์„œ์šธ์‹œ ๊ณต๊ณต๋ฐ์ดํ„ฐ ์‹œ๊ฐํ™”ํ•˜๊ธฐ

728x90

kibana๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์„œ์šธ์‹œ ๊ณต๊ณต๋ฐ์ดํ„ฐ ์‹œ๊ฐํ™”


โœ… ์‚ฌ์šฉํ•  ๊ณต๊ณต๋ฐ์ดํ„ฐ

https://data.seoul.go.kr/dataList/OA-20883/S/1/datasetView.do

 

์—ด๋ฆฐ๋ฐ์ดํ„ฐ๊ด‘์žฅ ๋ฉ”์ธ

๋ฐ์ดํ„ฐ๋ถ„๋ฅ˜,๋ฐ์ดํ„ฐ๊ฒ€์ƒ‰,๋ฐ์ดํ„ฐํ™œ์šฉ

data.seoul.go.kr

ํ•ด๋‹น ๊ณต๊ณต๋ฐ์ดํ„ฐ์˜ Open API๋ฅผ ํ™œ์šฉํ•œ๋‹ค.

์ธ์ฆํ‚ค๋ฅผ ๋ฐœ๊ธ‰๋ฐ›๋Š”๋‹ค.

 

โœ… ํŒŒ์ด์ฌ์„ ์ด์šฉํ•œ Open API ์‹คํ–‰

requests ๋ชจ๋“ˆ ์„ค์น˜

sudo apt install python3-pip
pip install requests

 

bulk API๋ฅผ ํ™œ์šฉํ•˜๋Š” ํŒŒ์ด์ฌ ํŒŒ์ผ ์ž‘์„ฑ

import urllib.request
from xml.etree.ElementTree import fromstring, ElementTree
from elasticsearch import Elasticsearch, helpers
es = Elasticsearch()
docs = []
for i in range (1, 21):
	  iStart = (i-l)*1000 + 1
		iEnd = i*1000
		url = 'http://openapi.seoul.go.kr: 8088/(((์ธ์ฆํ‚ค)))/xml/TbPublicWifiInfo/'+str(iStart)+'/'+str(iEnd)+'/'
		response = urllib.request.urlopen(url)
		xml_str = response.read().decode('utf-8')
		tree = ElementTree(fromstring(xml_str))
		root = tree.getroot()
				for row in root.iter("row"):
				gu_nm = row.find('X_SWIFI_WRDOFC').text
				place_nm = row.find('X_SWIFI_MAIN_NM').text
				place_x = float(row.find('LAT').text)
				place_y = float(row. find(' LNT'). text)
				doc = {
					".index": "seoulwifi2",
					"_source": {
					"gu_nm": gu_nm,
					"place_nm": place_nm,
					"instl_xy": {
					"lat": piace_x,
					"lon": place_y
				} 
		}
}
docs.append(doc)
print("END", iStart, "~"๏ผŒiEnd)
res = helpers.bulk(es, docs)
print("END")

๋ณธ์ธ์˜ ์ธ์ฆํ‚ค๋ฅผ url์— ๋„ฃ์–ด์„œ ์ž‘์„ฑํ•œ๋‹ค.

 

โœ… ํŒŒ์ด์ฌ์— elasticsearch client ์„ค์น˜

pip install elasticsearch

 

โœ…  ํ•œ๊ธ€ ๋ถ„์„๊ธฐ, ์œ„๊ฒฝ๋„ ๋ฐ์ดํ„ฐ ํƒ€์ž… ์ด์šฉํ•˜๊ธฐ ์œ„ํ•œ ์ธ๋ฑ์Šค ๋งคํ•‘

sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-nori
sudo systemctl restart elasticsearch

nori ์„ค์น˜ ๋ฐ es ์žฌ์‹คํ–‰

 

โœ…  elastic์—์„œ ๋ฏธ๋ฆฌ ์ธ๋ฑ์Šค๋ฅผ ์ƒ์„ฑ

PUT seoulwifi2
{
  "settings": {
    "analysis": {
      "analyzer": {
        "korean":{
          "tokenizer": "nori_tokenizer"
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "gu_nm": {"type": "keyword"},
      "place_nm": {"type": "text", "analyzer": "korean"},
      "instl_xy": {"type": "geo_point"}
    }
  }
}

 

โœ…  ์ธ๋ฑ์Šค ํŒจํ„ด ์ƒ์„ฑ

elastic - Stack Manager -  Index Patterns - Create New Pattern

seoulwifi* ๋กœ ์ธ๋ฑ์Šค ํŒจํ„ด ์ƒ์„ฑ

 

โœ…  Dev tools ์„œ GET์œผ๋กœ ํ™•์ธ

๊ฐœ์ˆ˜๊ฐ€ ์ข€ ๋ถ€์กฑํ•˜๋‹ค....

โœ…  ์‹œ๊ฐํ™”

elastic - Visualize Library - Create visualize - Explore options - Coordinate Map

 

์ƒ์„ฑํ•œ ์ธ๋ฑ์Šค ํŒจํ„ด์„ ํ™œ์šฉํ•˜์—ฌ ์ƒ์„ฑ

 

์‹œ๊ฐํ™”๋Š” ๋œ๋‹ค....

728x90