logstash + python
GET _search
{
"query": {
"match_all": {}
}
}
PUT movie
{
"settings": {
"number_of_shards": 5
},
"mappings": {
"doc": {
"properties" : {
"ord": {"type": "integer"},
"ele":{"type": "text"}
}
}
}
}
DELETE movie
GET movie/_count
GET movie/_search
GET movie/_search?q=*&sort=ord:dec&pretty
GET /movie/_search
{
"query": {"match_all": { } },
"sort": [
{ "ord":"asc" }
],
"size": 20
}
GET /movie/_search
{
"query": {"match_all": { } },
"sort": [
{ "ord":"asc" }
],
"from": 10,
"size":10
}
GET /movie/_search
{
"query": { "match_all" : { } },
"sort": { "ord": { "order": "desc" } }
}
=========================================================================================================================
from bs4 import BeautifulSoup
import json
import requests
import elasticsearch
class OrderList:
def __init__(self):
self.target_url = "https://www.naver.com/"
self.elements = None
self.es = elasticsearch.Elasticsearch()
# requests
def UrlRequests(self):
html = requests.get(url= self.target_url)
if html.status_code == 200:
bs_obj = BeautifulSoup(html.text, "html.parser")
ordered_lst = bs_obj.select_one("ul.ah_l")
secondlst = ordered_lst.select("li.ah_item > a > span:nth-of-type(2)")
self.elements = [{"ord":i+1, "ele":e.string} for i, e in enumerate(secondlst)]
html.close()
print(self.elements)
# json 파일 만들기
def JsonFileMake(self):
with open("./File_json/naver_list.json", "w", encoding="utf-8") as f:
json.dump(self.elements, f, ensure_ascii=False)
f.close()
# json 파일 읽어 오기
def JsonFileRead(self):
with open("./File_json/naver_list.json", "r", encoding="utf-8") as f:
json_file = json.loads(f.read())
print (json_file)
f.close()
node = OrderList() # object
node.UrlRequests()
node.JsonFileMake()
node.JsonFileRead()
'ELK > logstash' 카테고리의 다른 글
logstash file json absolute path (0) | 2020.06.17 |
---|---|
logstash input-plugin (elasticsearch) (0) | 2020.05.12 |
logstash plugin install (0) | 2020.04.15 |
logstash + app-search (0) | 2019.12.10 |
logstash - mysql - elasticsearch 연동 (0) | 2019.01.06 |