private List <IndexInformation> GetIndices()
        {
            var indexHelper = new Admin.Index(_settings, _httpClientHelper, "GetIndices-NA");

            var indices = indexHelper.GetIndices().ToList();

            var config = ElasticSearchSection.GetConfiguration();

            foreach (var indexInfo in indices)
            {
                var parsed = config.IndicesParsed
                             .OrderByDescending(i => i.Name.Length)
                             .FirstOrDefault(i => indexInfo.Index.StartsWith(i.Name, StringComparison.InvariantCultureIgnoreCase));

                indexInfo.Type = String.IsNullOrWhiteSpace(parsed?.Type)
                    ? "[default]"
                    : Type.GetType(parsed.Type)?.Name;

                var displayName = new StringBuilder(parsed?.DisplayName);

                if (indexInfo.Index.Contains($"-{Constants.CommerceProviderName}".ToLowerInvariant()))
                {
                    displayName.Append(" Commerce");
                }

                indexInfo.DisplayName = displayName.ToString();
            }

            return(indices);
        }
        private ActionResult GetJsonFromEndpoint(string index, string endpoint)
        {
            if (String.IsNullOrWhiteSpace(index))
            {
                index = CurrentIndex;
            }

            var indexHelper = new Admin.Index(_settings, _httpClientHelper, index);

            var indices = indexHelper.GetIndices()
                          .Select(i => i.Index).ToList();

            ViewBag.Indices  = indices;
            ViewBag.Endpoint = endpoint;

            if (!indices.Contains(index))
            {
                return(View("~/Views/ElasticSearchAdmin/Console/_JsonDump.cshtml"));
            }

            ViewBag.SelectedIndex = index;

            string uri      = $"{_settings.Host}/{index}/_{endpoint}";
            string response = _httpClientHelper.GetJson(new Uri(uri));

            ViewBag.Result = JToken.Parse(response).ToString(Formatting.Indented);

            return(View("~/Views/ElasticSearchAdmin/Console/_JsonDump.cshtml"));
        }
Example #3
0
 internal ElasticSynonymsController(
     ISynonymRepository synonymRepository,
     ILanguageBranchRepository languageBranchRepository,
     Admin.Index indexHelper)
 {
     _synonymRepository        = synonymRepository;
     _languageBranchRepository = languageBranchRepository;
     _indexHelper = indexHelper;
 }
 internal ElasticTrackingController(
     IContentLoader contentLoader,
     ILanguageBranchRepository languageBranchRepository,
     ITrackingRepository trackingRepository,
     Admin.Index indexHelper)
 {
     _languageBranchRepository = languageBranchRepository;
     _trackingRepository       = trackingRepository;
     _indexHelper = indexHelper;
 }
Example #5
0
 internal ElasticBestBetsController(
     IContentLoader contentLoader,
     IBestBetsRepository bestBetsRepository,
     ILanguageBranchRepository languageBranchRepository,
     Admin.Index indexHelper)
 {
     _contentLoader            = contentLoader;
     _bestBetsRepository       = bestBetsRepository;
     _languageBranchRepository = languageBranchRepository;
     _indexHelper = indexHelper;
 }
        public ActionResult Index(string query, string index)
        {
            if (String.IsNullOrWhiteSpace(index))
            {
                index = CurrentIndex;
            }

            var indexHelper = new Admin.Index(_settings, _httpClientHelper, index);

            List <string> indices = indexHelper.GetIndices()
                                    .Select(i => i.Index).ToList();

            if (!indices.Contains(index))
            {
                index = CurrentIndex;
            }

            ViewBag.Indices       = indices;
            ViewBag.SelectedIndex = index;

            if (String.IsNullOrWhiteSpace(query))
            {
                query = "{\n    \"size\" : 10,\n    \"query\" : {\n        \"match_all\" : {}\n    }\n}";
            }

            ViewBag.Query = query;

            if (String.IsNullOrWhiteSpace(index) || !indices.Contains(index))
            {
                return(View("~/Views/ElasticSearchAdmin/Console/Index.cshtml"));
            }

            string uri = $"{_settings.Host}/{index}/_search";

            if (Core.Server.Info.Version.Major >= 7)
            {
                uri += "?rest_total_hits_as_int=true";
            }

            byte[] data       = Encoding.UTF8.GetBytes(query);
            byte[] returnData = _httpClientHelper.Post(new Uri(uri), data);
            string response   = Encoding.UTF8.GetString(returnData);

            ViewBag.Result = JToken.Parse(response).ToString(Formatting.Indented);

            return(View("~/Views/ElasticSearchAdmin/Console/Index.cshtml"));
        }