protected string CreateMapFor(Type t) { var type = TypeNameMarker.Create(t); var writer = new TypeMappingWriter(t, type, TestElasticClient.Settings, 10); return(writer.MapFromAttributes()); }
private static BulkRequest CreateIndexBulkRequest <T>(IEnumerable <T> objects, Func <T, string> getIndex, string type, Func <T, string> getParent) where T : class { var bulkRequest = new BulkRequest(); TypeNameMarker typeNameMarker = type; bulkRequest.Type = typeNameMarker; var list = objects.Select(o => { var doc = new BulkIndexOperation <T>(o); if (getParent != null) { doc.Parent = getParent(o); } if (getIndex != null) { doc.Index = getIndex(o); } var versionedDoc = o as IVersioned; if (versionedDoc != null) { doc.Version = versionedDoc.Version.ToString(); } return(doc); }).Cast <IBulkOperation>().ToList(); bulkRequest.Operations = list; return(bulkRequest); }
/// <summary> /// The type to execute the search on. Defaults to the inferred typename of T /// unless T is dynamic then a type (or AllTypes()) MUST be specified. /// </summary> public TDescriptor Type(TypeNameMarker type) { if (type == null) { return((TDescriptor)this); } return(this.Types(type)); }
public ObjectMappingDescriptor(IConnectionSettingsValues connectionSettings) { this._TypeName = TypeNameMarker.Create <TChild>(); this._Mapping = new ObjectMapping() { }; this._connectionSettings = connectionSettings; this.Infer = new ElasticInferrer(this._connectionSettings); }
internal string GetTypeNameFor(TypeNameMarker t) { if (t == null) { return(null); } return(t.Name ?? this.GetTypeNameFor(t.Type)); }
public PutMappingDescriptor <T> SetParent <K>() where K : class { var parentType = TypeNameMarker.Create <K>(); Self.Mapping.Parent = new ParentTypeMapping() { Type = parentType }; return(this); }
public TypeMappingWriter(Type t, TypeNameMarker typeName, IConnectionSettings connectionSettings, int maxRecursion) { this._type = t; this._connectionSettings = connectionSettings; this.TypeName = typeName; this.MaxRecursion = maxRecursion; this.SeenTypes = new ConcurrentDictionary<Type, int>(); this.SeenTypes.TryAdd(t, 0); }
public TypeMappingWriter(Type t, TypeNameMarker typeName, IConnectionSettings connectionSettings, int maxRecursion) { this._type = t; this._connectionSettings = connectionSettings; this.TypeName = typeName; this.MaxRecursion = maxRecursion; this.SeenTypes = new ConcurrentDictionary <Type, int>(); this.SeenTypes.TryAdd(t, 0); }
public void AttributeTypeNamesTakePrecedenceOverDefaultTypeNameInferrer() { var clientSettings = new ConnectionSettings(Test.Default.Uri, "mydefaultindex") .SetDefaultTypeNameInferrer(t => t.Name.ToUpperInvariant()) ; var inferrer = new ElasticInferrer(clientSettings); TypeNameMarker marker = typeof(MyCustomAtrributeName); inferrer.TypeName(marker).Should().Be("custotypo"); }
public void TypeNameMarkerEqualsDoesNotUseHashCode() { var collision = GetHashCollison(); var typeNameMarker1 = new TypeNameMarker { Name = collision.Item1 }; var typeNameMarker2 = new TypeNameMarker { Name = collision.Item2 }; this.TestAddingToDictionary(typeNameMarker1, typeNameMarker2); }
public DeleteByQueryRequest(IndexNameMarker index, TypeNameMarker type = null) { this.Indices = new [] { index }; if (type != null) { this.Types = new[] { type } } ; else { this.AllTypes = true; } }
public void MapTypeIndicesTakesPrecedenceOverAttributeName() { var clientSettings = new ConnectionSettings(Test.Default.Uri, "mydefaultindex") .MapDefaultTypeNames(dt => dt .Add(typeof(MyCustomAtrributeName), "micutype") ) .SetDefaultTypeNameInferrer(t => t.Name.ToUpperInvariant()) ; var inferrer = new ElasticInferrer(clientSettings); TypeNameMarker marker = typeof(MyCustomAtrributeName); inferrer.TypeName(marker).Should().Be("micutype"); }
public TypeMappingWriter(Type t, TypeNameMarker typeName, IConnectionSettingsValues connectionSettings, int maxRecursion) { this._type = t; this._connectionSettings = connectionSettings; this.TypeName = typeName; this.MaxRecursion = maxRecursion; this.SeenTypes = new ConcurrentDictionary<Type, int>(); this.SeenTypes.TryAdd(t, 0); this._elasticSerializer = new NestSerializer(this._connectionSettings); this.Infer = new ElasticInferrer(this._connectionSettings); }
public TypeMappingWriter(Type t, TypeNameMarker typeName, IConnectionSettingsValues connectionSettings, int maxRecursion) { this._type = t; this._connectionSettings = connectionSettings; this.TypeName = typeName; this.MaxRecursion = maxRecursion; this.SeenTypes = new ConcurrentDictionary <Type, int>(); this.SeenTypes.TryAdd(t, 0); this._elasticSerializer = new NestSerializer(this._connectionSettings); this.Infer = new ElasticInferrer(this._connectionSettings); }
public IOpenSearchableElasticType GetOpenSearchableElasticTypeByNameOrDefault(string indexName, string typeName, Dictionary <string, object> parameters = null) { var indexNameMarker = new IndexNameMarker(); indexNameMarker.Name = indexName; var typeNameMarker = new TypeNameMarker(); typeNameMarker.Name = typeName; IOpenSearchableElasticType type = GetOpenSearchableElasticTypeByName(indexName, typeName); if (type == null) { type = new GenericJsonOpenSearchable(indexName, typeName); } return(type); }
public void DefaultTypeNamesTakePrecedenceOverCustomTypeNameInferrer() { var clientSettings = new ConnectionSettings(Test.Default.Uri, "mydefaultindex") .MapDefaultTypeNames(p => p .Add(typeof(Developer), "codemonkey") ) .SetDefaultTypeNameInferrer(t => t.Name.ToUpperInvariant()) ; var inferrer = new ElasticInferrer(clientSettings); TypeNameMarker marker = typeof(Developer); inferrer.TypeName(marker).Should().Be("codemonkey"); //Should use the custom type name inferrer that upper cases marker = typeof(NoopObject); inferrer.TypeName(marker).Should().Be("NOOPOBJECT"); }
private static BulkRequest CreateIndexBulkRequest <T>(IEnumerable <T> objects, Func <T, string> getIndex, string type, Func <T, string> getParent) where T : class { if (objects == null) { throw new ArgumentNullException(nameof(objects)); } var bulkRequest = new BulkRequest(); TypeNameMarker typeNameMarker = type; bulkRequest.Type = typeNameMarker; var list = objects.Select(o => new BulkIndexOperation <T>(o) { Parent = getParent?.Invoke(o), Index = getIndex?.Invoke(o), }).Cast <IBulkOperation>().ToList(); bulkRequest.Operations = list; return(bulkRequest); }
public void ResolveToSepcifiedTypeNames() { var clientSettings = new ConnectionSettings(Test.Default.Uri, "mydefaultindex") .MapDefaultTypeNames(p => p .Add(typeof(Car), "automobile") .Add(typeof(Person), "human") .Add(typeof(Organization), "organisation") .Add(typeof(Developer), "codemonkey") .Add(typeof(MyGeneric <Developer>), "codemonkey-wrapped-in-bacon") .Add(typeof(MyGeneric <Organization>), "org-wrapped-in-bacon") ); var inferrer = new ElasticInferrer(clientSettings); TypeNameMarker marker = typeof(Car); inferrer.TypeName(marker).Should().Be("automobile"); marker = typeof(Person); inferrer.TypeName(marker).Should().Be("human"); marker = typeof(Organization); inferrer.TypeName(marker).Should().Be("organisation"); marker = typeof(Developer); inferrer.TypeName(marker).Should().Be("codemonkey"); marker = typeof(MyGeneric <Developer>); inferrer.TypeName(marker).Should().Be("codemonkey-wrapped-in-bacon"); marker = typeof(MyGeneric <Organization>); inferrer.TypeName(marker).Should().Be("org-wrapped-in-bacon"); //Should fall back to the default lowercase since //it doesn't have an explicit default marker = typeof(NoopObject); inferrer.TypeName(marker).Should().Be("noopobject"); }
public IOpenSearchableElasticType GetOpenSearchableElasticTypeByName(string indexName, string typeName, Dictionary <string, object> parameters = null) { foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes(typeof(IOpenSearchableElasticType))) { IOpenSearchableElasticType etype = (IOpenSearchableElasticType)node.CreateInstance(); if (etype.Identifier == typeName) { Type type = node.Type; var ctor = type.GetConstructor(new Type[2] { typeof(IndexNameMarker), typeof(TypeNameMarker) }); var indexNameMarker = new IndexNameMarker(); indexNameMarker.Name = indexName; var typeNameMarker = new TypeNameMarker(); typeNameMarker.Name = typeName; etype = (IOpenSearchableElasticType)ctor.Invoke(new object[2] { indexNameMarker, typeNameMarker }); etype.Parameters = parameters; return(etype); } } return(null); }
/// <summary> /// Calls putmapping on /{indices}/{type} /// </summary> public PutMappingRequest(IEnumerable <IndexNameMarker> indices, TypeNameMarker type) { this.Type = type; this.Indices = indices; }
public IOpenSearchableElasticType GetOpenSearchableElasticTypeByName(string indexName, string typeName, Dictionary<string, object> parameters = null) { foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes (typeof(IOpenSearchableElasticType))) { IOpenSearchableElasticType etype = (IOpenSearchableElasticType)node.CreateInstance(); if (etype.Identifier == typeName) { Type type = node.Type; var ctor = type.GetConstructor(new Type[2]{ typeof(IndexNameMarker), typeof(TypeNameMarker) }); var indexNameMarker = new IndexNameMarker(); indexNameMarker.Name = indexName; var typeNameMarker = new TypeNameMarker(); typeNameMarker.Name = typeName; etype = (IOpenSearchableElasticType)ctor.Invoke(new object[2]{ indexNameMarker, typeNameMarker }); etype.Parameters = parameters; return etype; } } return null; }
internal static bool IsNullOrEmpty(this TypeNameMarker value) { return(value == null || value.GetHashCode() == 0); }
public IOpenSearchableElasticType GetOpenSearchableElasticTypeByNameOrDefault(string indexName, string typeName, Dictionary<string, object> parameters = null) { var indexNameMarker = new IndexNameMarker(); indexNameMarker.Name = indexName; var typeNameMarker = new TypeNameMarker(); typeNameMarker.Name = typeName; IOpenSearchableElasticType type = GetOpenSearchableElasticTypeByName(indexName, typeName); if (type == null) { type = new GenericJsonOpenSearchable(indexName, typeName); } return type; }
public TopChildrenQueryDescriptor() { ((ITopChildrenQuery)this).Type = TypeNameMarker.Create <T>(); }
/// <summary> /// Calls putmapping on /_all/{type} /// </summary> public PutMappingRequest(TypeNameMarker type) { this.Type = type; this.AllIndices = true; }
protected MultiFieldMapping(TypeNameMarker defaultType) : this() { _defaultType = defaultType; }
public GenericJsonOpenSearchable(IndexNameMarker index, TypeNameMarker type) { this.type = type; this.index = index; }
/// <summary> /// Calls putmapping on /{index}/{type} /// </summary> public PutMappingRequest(IndexNameMarker index, TypeNameMarker type) { this.Type = type; this.Indices = new [] { index }; }
public MultiFieldMapping() { this.Fields = new Dictionary<PropertyNameMarker, IElasticCoreType>(); _defaultType = "multi_field"; }
public DocumentOptionalPathBase(IndexNameMarker indexName, TypeNameMarker typeName, string id) { this.Index = indexName; this.Type = typeName; this.Id = id; }
public static bool IsConditionless(this TypeNameMarker marker) { return(marker == null || marker.Name.IsNullOrEmpty() && marker.Type == null); }
public SourceRequest(IndexNameMarker indexName, TypeNameMarker typeName, string id) : base(indexName, typeName, id) { }
public MoreLikeThisRequest(IndexNameMarker indexName, TypeNameMarker typeName, string id) : base(indexName, typeName, id) { }
protected DocumentPathBase(IndexNameMarker indexName, TypeNameMarker typeName, string id) : base(indexName, typeName, id) { }
public MultiTermVectorsRequest(IndexNameMarker index, TypeNameMarker typeNameMarker) : base(index, typeNameMarker) { }
public IndexTypePathBase(IndexNameMarker index, TypeNameMarker typeNameMarker) { this.Index = index; this.Type = typeNameMarker; }