nest - Programmatic PUT mapping for a type isn't being used? -
i've defined programmatic mapping type following example in fluent api unit test (fluentmappingfullexampletests) so:
_client.map<sometype>(m => m .type("mytype") ...
i add instance of sometype index via call like
_client.index<sometype>(instance)
however, when go searching instance, don't find instances of 'mytype'; instead, there's instance of 'sometype', , new type mapping has been created 'sometype'. have expected put mapping honored when performed insertion.
am not using put mappings way should used? unfortunately, unit test doesn't demonstrate round-tripping, i'm unsure if there's else should doing.
edit: bears mentioning i'm trying achieve 100% programmatic mapping, here; no next attributes on type.
i able handle use case in example:
//request url: http://localhost:9200/indexname var indicesoperationresponse = client.createindex(indexname); //request url: http://localhost:9200/indexname/document2/_mapping var response = client.map<document>(m => m .type("document2") .properties(p => p.string(s => s.name(n => n.name).index(fieldindexoption.notanalyzed)))); //request url: http://localhost:9200/indexname/document2/1 client.index(new document { id = 1, name = "test"}); client.refresh(); //request url: http://localhost:9200/indexname/document2/_search var searchresponse = client.search<document>(s => s.query(q => q.matchall()));
key thing mark document
class elastictype
attribute:
[elastictype(name = "document2")] public class document { public int id { get; set; } public string name { get; set; } }
hope helps you.
update
your comment makes sense. instead of using elastictype
can change type name inference elasticclient
.
var uri = new uri("http://localhost:9200"); var settings = new connectionsettings(uri) .setdefaultindex(indexname) .mapdefaulttypenames(d => d.add(typeof(document), "document2")) var client = new elasticclient(settings);
so can remove attribute document
class
public class document { public int id { get; set; } public string name { get; set; } }
we don't need specify type alias in mapping:
var response = client.map<document>(m => m .properties(p => p.string(s => s.name(n => n.name).index(fieldindexoption.notanalyzed))));
Comments
Post a Comment