개요

말이 조금 어려운데 키바나에서 ES 검색을 호출할때 쓰는 request를 hooking하여 curl로 변환해 보았다. 쓰임새는 아직 비밀이다.

curl

curl에 필요한 test파일을 아래와 같이 생성하면 된다.

curl -s -XPOST -L 'http://esurl/_msearch' --data-binary "@test"

test 파일

{"index":["인덱스이름"],"ignore_unavailable":true,"preference":1513646426988}
{"query":{"bool":{"must":[{"query_string":{"query":"*","analyze_wildcard":true}},{"query_string":{"query":"*","analyze_wildcard":true}},{"range":{"ts":{"gte":1513646896942,"lte":1513647796942,"format":"epoch_millis"}}}],"must_not":[]}},"size":0,"_source":{"excludes":[]},"aggs":{"2":{"date_histogram":{"field":"ts","interval":"1m","time_zone":"Asia/Tokyo","min_doc_count":1},"aggs":{"1":{"sum":{"field":"datapoint"}}}}},"version":true,"highlight":{"pre_tags":["@kibana-highlighted-field@"],"post_tags":["@/kibana-highlighted-field@"],"fields":{"*":{"highlight_query":{"bool":{"must":[{"query_string":{"query":"*","analyze_wildcard":true,"all_fields":true}},{"query_string":{"query":"*","analyze_wildcard":true,"all_fields":true}},{"range":{"ts":{"gte":1513646896942,"lte":1513647796942,"format":"epoch_millis"}}}],"must_not":[]}}}},"fragment_size":2147483647}}

대안

파일로 따로 생성하는게 귀찮다면 아래와 같이 해도 된다. 핵심은 json 한줄마다 엔터를 띄워줘야 하는 것이다.

curl -s -XPOST -L 'http://esurl/_msearch' --data-binary '{"index":["인덱스이름"],"ignore_unavailable":true,"preference":1513646426988}
{"query":{"bool":{"must":[{"query_string":{"query":"*","analyze_wildcard":true}},{"query_string":{"query":"*","analyze_wildcard":true}},{"range":{"ts":{"gte":1513646896942,"lte":1513647796942,"format":"epoch_millis"}}}],"must_not":[]}},"size":0,"_source":{"excludes":[]},"aggs":{"2":{"date_histogram":{"field":"ts","interval":"1m","time_zone":"Asia/Tokyo","min_doc_count":1},"aggs":{"1":{"sum":{"field":"datapoint"}}}}},"version":true,"highlight":{"pre_tags":["@kibana-highlighted-field@"],"post_tags":["@/kibana-highlighted-field@"],"fields":{"*":{"highlight_query":{"bool":{"must":[{"query_string":{"query":"*","analyze_wildcard":true,"all_fields":true}},{"query_string":{"query":"*","analyze_wildcard":true,"all_fields":true}},{"range":{"ts":{"gte":1513646896942,"lte":1513647796942,"format":"epoch_millis"}}}],"must_not":[]}}}},"fragment_size":2147483647}}
'