반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- ElasticSearch
- 코딩테스트
- intervals
- urllib3
- low level client
- mkdirs
- ES Query
- codility
- AbsDistinct 풀이
- es test data
- 5amsung
- flow chart
- java set
- high level client
- 카드모으기 자바
- Collectors.toMap
- Draw.IO
- java
- Warnings
- AbsDistinct java
- mkdir
- collect
- AbsDistinct
- ELK
- es
- analyze api
- elasticsearch java
- draw.io down
- Elastic Stack
- https warning
Archives
- Today
- Total
5AMSUNG
[python] kibana 에서 쓰던 쿼리 조회 하기 본문
반응형
키바나에서 쓰던 쿼리를 바로 조회 해보자
high level client 를 사용를 사용하고 있는 api 에서 쿼리를 추출해보면 아래과 같은
형태가 나오는데 ..
이걸 데이터를 뽑아서 증거품을 만들어야 하는 상황..
근데 python 소스에 string 으로 발라서 넣으려고 하니까
true 라든지.. 숫자라든지..
암튼 걸리는 것들이 있어
json 파일로 만들어서 불러오는 방법 사용
json 파일 셈플
{
"from": 0,
"size": 20,
"timeout": "60s",
"query": {
"bool": {
"filter": [{
"range": {
"saleStartDt": {
"from": null,
"to": "now/m",
"include_lower": true,
"include_upper": true,
"boost": 1.0
}
}
}, {
"range": {
"saleEndDt": {
"from": "now/m",
"to": null,
"include_lower": true,
"include_upper": true,
"boost": 1.0
}
}
}, {
"multi_match": {
"query": "Y",
"fields": ["docDispYn^1.0", "rsvDocDispYn^1.0"],
"type": "best_fields",
"operator": "OR",
"slop": 0,
"prefix_length": 0,
"max_expansions": 50,
"zero_terms_query": "NONE",
"auto_generate_synonyms_phrase_query": true,
"fuzzy_transpositions": true,
"boost": 1.0
}
}, {
"bool": {
"should": [{
"terms": {
"itemStoreInfo.storeId": ["37", "20163"],
"boost": 1.0
}
}, {
"term": {
"shipMethod": {
"value": "TD_DLV",
"boost": 1.0
}
}
}, {
"term": {
"storeType": {
"value": "DS",
"boost": 1.0
}
}
}],
"adjust_pure_negative": true,
"boost": 1.0
}
}, {
"term": {
"category.mcateCd": {
"value": 200390,
"boost": 1.0
}
}
}, {
"range": {
"itemStoreInfo.weight": {
"from": null,
"to": 0.0,
"include_lower": true,
"include_upper": true,
"boost": 1.0
}
}
}],
"adjust_pure_negative": true,
"boost": 1.0
}
},
"sort": [{
"adultSort": {
"order": "asc"
}
}, {
"itemStoreInfo.weight": {
"order": "desc"
}
}, {
"itemStoreInfo.sortWeight": {
"order": "desc"
}
}, {
"itemStoreInfo.buyerCnt": {
"order": "desc"
}
}, {
"itemNo": {
"order": "desc"
}
}]
}
code
# -*- coding: utf-8 -*-
import time
from elasticsearch import Elasticsearch
def ingi():
with open(QUERY_INGI) as index_file:
source = index_file.read().strip()
response = client.search(index=INDEX_NAME, body=source)
print("== 인기와인 == ")
for hit in response["hits"]["hits"]:
print(hit["_source"]["itemNm"] +" ( " + str(hit["_source"]["itemNo"]) + "sortWeight - 가중치값 : "+ str(hit["_source"]["itemStoreInfo"]["sortWeight"] )+")")
def chuchun():
with open(CHU_CHUN) as index_file:
source = index_file.read().strip()
response = client.search(index=INDEX_NAME, body=source)
print("== 추천와인 == ")
for hit in response["hits"]["hits"]:
print(hit["_source"]["itemNm"] +" ( " + str(hit["_source"]["itemNo"]) + "weight - 가중치값 : " + str(hit["_source"]["itemStoreInfo"]["weight"] ) + "sortWeight - 가중치값 : "+ str(hit["_source"]["itemStoreInfo"]["sortWeight"] )+")")
print()
def ipmun():
with open(CHU_CHUN) as index_file:
source = index_file.read().strip()
response = client.search(index=INDEX_NAME, body=source)
print("== 입문 == ")
for hit in response["hits"]["hits"]:
print(hit["_source"]["itemNm"] +" ( " + str(hit["_source"]["itemNo"]) + "sortWeight - 가중치값 : "+ str(hit["_source"]["itemStoreInfo"]["sortWeight"] )+")")
print()
def ingi_wi():
with open(INGI_WI) as index_file:
source = index_file.read().strip()
response = client.search(index=INDEX_NAME, body=source)
print("== 인기위스키 == ")
for hit in response["hits"]["hits"]:
print(hit["_source"]["itemNm"] +" ( " + str(hit["_source"]["itemNo"]) + "sortWeight - 가중치값 : "+ str(hit["_source"]["itemStoreInfo"]["sortWeight"] )+")")
print()
def chuchun_wi():
with open(CHU_CHUN_WI) as index_file:
source = index_file.read().strip()
response = client.search(index=INDEX_NAME, body=source)
print("== 추천위스키 == ")
for hit in response["hits"]["hits"]:
print(hit["_source"]["itemNm"] +" ( " + str(hit["_source"]["itemNo"]) + "sortWeight - 가중치값 : "+ str(hit["_source"]["itemStoreInfo"]["sortWeight"] )+")")
print()
##### MAIN SCRIPT #####
if __name__ == '__main__':
INDEX_NAME = "hyper-item"
QUERY_INGI = "easypickup/sql/ingi.json"
CHU_CHUN = "easypickup/sql/chuchun.json"
IPMUN = "easypickup/sql/ipmun.json"
INGI_WI = "easypickup/sql/ingi_wi.json"
CHU_CHUN_WI = "easypickup/sql/chuchun_wi.json"
client = Elasticsearch("https://elastic:elastic1!@category-es-qa.homeplus.kr:443/", ca_certs=False,
verify_certs=False)
ingi()
print()
chuchun()
print()
ipmun()
print()
ingi_wi()
print()
chuchun_wi()
print()
print("Done.")
결과 값
반응형