using System.Net;
using System.Text;

namespace XYY.Data.Model.Standard.Tracking.TrackingTraces
{
    public class ESRequest
    {
        string es_host;
        string es_index;
        string es_type;
        private string url;

        public ESRequest(string host, string index, string type, string operName)
        {
            es_host = host;
            es_index = index;
            es_type = type;

            url = string.Format("{0}/{1}/{2}/_{3}", es_host, es_index, es_type, operName);
        }

        public string ExecuteQeury(string json_query)
        {
            WebClient client = new WebClient();
            client.Headers.Add("Accept", "*/*");
            client.Headers.Add("User-Agent", "PostmanRuntime/7.26.1");
            client.Headers.Add("Content-Type", "application/json");

            byte[] data = Encoding.UTF8.GetBytes(json_query);
            var resultData = client.UploadData(url, data);
            string result = Encoding.UTF8.GetString(resultData);
            return result;

        }
    }
}
