Ejemplo n.º 1
0
        internal GetMappingResponse(GetRootObjectMappingWrapping dict)
        {
            if (dict == null)
            {
                return;
            }
            foreach (var index in dict)
            {
                if (index.Value == null || !index.Value.TryGetValue("mappings", out var mappings))
                {
                    continue;
                }
                this._mappings.Add(index.Key, new Dictionary <string, TypeMapping>());
                foreach (var mapping in mappings)
                {
                    if (mapping.Value == null)
                    {
                        continue;
                    }
                    this._mappings[index.Key].Add(mapping.Key, mapping.Value);
                }
            }

            this.Mapping = this.Mappings.Where(kv => kv.Value.HasAny(v => v.Value != null))
                           .SelectMany(kv => kv.Value)
                           .FirstOrDefault(t => t.Value != null).Value;
        }
Ejemplo n.º 2
0
        internal GetMappingResponse(ConnectionStatus status, GetRootObjectMappingWrapping dict)
        {
            this.IsValid = status.Success && dict != null && dict.Count > 0;
            if (!this.IsValid)
            {
                return;
            }
            var firstNode = dict.First();

            if (!firstNode.Value.HasAny())
            {
                return;
            }
            var mappingNode = firstNode.Value["mappings"];

            if (mappingNode == null)
            {
                this.IsValid = false;
                return;
            }
            var mapping = mappingNode.First();

            if (mapping.Value == null)
            {
                this.IsValid = false;
                return;
            }
            mapping.Value.Name = mapping.Key;
            this.Mapping       = mapping.Value;
        }
Ejemplo n.º 3
0
        internal GetMappingResponse(IElasticsearchResponse status, GetRootObjectMappingWrapping dict)
        {
            this.Mappings = new Dictionary <string, IList <TypeMapping> >();
            this.IsValid  = status.Success && dict != null && dict.Count > 0;
            if (!this.IsValid)
            {
                return;
            }
            foreach (var index in dict)
            {
                if (index.Value == null || !index.Value.ContainsKey("mappings"))
                {
                    continue;
                }

                var mappings = index.Value["mappings"];
                this.Mappings.Add(index.Key, new List <TypeMapping>());
                if (mappings == null)
                {
                    continue;
                }
                foreach (var mapping in mappings)
                {
                    if (mapping.Value == null)
                    {
                        continue;
                    }
                    var typeMapping = new TypeMapping
                    {
                        TypeName = mapping.Key,
                        Mapping  = mapping.Value
                    };
                    mapping.Value.Name = mapping.Key;
                    this.Mappings[index.Key].Add(typeMapping);
                }
            }

            this.Mapping = this.Mappings.Where(kv => kv.Value.HasAny(v => v.Mapping != null))
                           .SelectMany(kv => kv.Value)
                           .Select(tm => tm.Mapping)
                           .FirstOrDefault(t => t != null);
        }
Ejemplo n.º 4
0
        internal GetMappingResponse(IApiCallDetails status, GetRootObjectMappingWrapping dict)
        {
            this.Mappings = new Dictionary <string, IList <TypeMapping> >();
            //TODO can dict truely ever be null, whats the response look like when field mapping is not found.
            //does status.Success not already reflect this?
            //this.IsValid = status.Success && dict != null && dict.Count > 0;
            if (!status.Success || dict == null)
            {
                return;
            }

            foreach (var index in dict)
            {
                if (index.Value == null || !index.Value.ContainsKey("mappings"))
                {
                    continue;
                }

                var mappings = index.Value["mappings"];
                this.Mappings.Add(index.Key, new List <TypeMapping>());
                if (mappings == null)
                {
                    continue;
                }
                foreach (var mapping in mappings)
                {
                    if (mapping.Value == null)
                    {
                        continue;
                    }
                    this.Mappings[index.Key].Add(mapping.Value);
                }
            }

            this.Mapping = this.Mappings.Where(kv => kv.Value.HasAny(v => v != null))
                           .SelectMany(kv => kv.Value)
                           .FirstOrDefault(t => t != null);
        }