Пример #1
0
        public IEnumerable <Field> GetFields(string name)
        {
            var version = ElasticVersionParser.ParseVersion(_input);
            ElasticsearchResponse <DynamicResponse> response;

            if (version.Major >= 7)
            {
                response = _client.IndicesGetMapping <DynamicResponse>(_index, name, qs => qs.AddQueryString("include_type_name", "true"));
            }
            else
            {
                response = _client.IndicesGetMapping <DynamicResponse>(_index, name);
            }

            if (response.Success)
            {
                var properties = response.Body[_index]["mappings"][name]["properties"] as ElasticsearchDynamicValue;
                if (properties != null && properties.HasValue)
                {
                    return(PropertiesToFields(name, properties.Value as IDictionary <string, object>));
                }
                _input.Error("Could not find properties for index {0} type {1}.", _index, name);
            }
            else
            {
                _input.Error(response.ToString());
            }

            return(Enumerable.Empty <Field>());
        }
Пример #2
0
        public IEnumerable<Entity> GetEntities()
        {
            var response = _client.IndicesGetMapping<DynamicResponse>(_index, "_all");

            if (response.Success) {
                var mappings = response.Body[_index]["mappings"] as ElasticsearchDynamicValue;
                if (mappings != null && mappings.HasValue) {
                    var types = mappings.Value as IDictionary<string, object>;
                    if (types != null) {
                        foreach (var pair in types) {
                            var e = new Entity { Name = pair.Key }.WithDefaults();
                            var attributes = pair.Value as IDictionary<string, object>;
                            if (attributes != null && attributes.ContainsKey("properties")) {
                                e.Fields = PropertiesToFields(pair.Key, attributes["properties"] as IDictionary<string, object>).ToList();
                            } else {
                                _input.Error("Could not find properties for index {0} type {1}.", _input, pair.Key);
                            }
                            yield return e;
                        }
                    } else {
                        _input.Error("Could not find types in index {0}.", _index);
                    }
                } else {
                    _input.Error("Could not find mappings for index {0}.", _index);
                }
            } else {
                _input.Error(response.ToString());
            }
        }
Пример #3
0
        public IEnumerable <Field> GetFields(string name)
        {
            var response = _client.IndicesGetMapping <DynamicResponse>(_index, name);

            if (response.Success)
            {
                var properties = response.Body[_index]["mappings"][name]["properties"] as ElasticsearchDynamicValue;
                if (properties != null && properties.HasValue)
                {
                    return(PropertiesToFields(name, properties.Value as IDictionary <string, object>));
                }
                _input.Error("Could not find properties for index {0} type {1}.", _index, name);
            }
            else
            {
                _input.Error(response.ToString());
            }

            return(Enumerable.Empty <Field>());
        }