我正在尝试使用流利的方式将MyCode
属性映射到我的对象(已下载)为NotAnalyzed
。
我已经审核过了: Creating an index Nest和 Nest and Elastic Search - Mapping
{
"myobject_test" : {
"mappings" : {
"myversion" : {
"properties" : {
"id" : {
"type" : "long"
},
"isLatest" : {
"type" : "boolean"
},
"maxVersion" : {
"type" : "long"
},
"original" : {
"properties" : {
"agent" : {
"properties" : {
"name" : {
"type" : "string"
},
"organizationId" : {
"type" : "long"
},
"version" : {
"type" : "long"
}
}
},
"agentReference" : {
"type" : "string"
},
"myCode" : {
"type" : "string"
},
"myDate" : {
"type" : "date",
"format" : "dateOptionalTime"
},
"netWorth" : {
"type" : "double"
},
"objectVersionId" : {
"type" : "long"
},
"myOrganization" : {
"properties" : {
"name" : {
"type" : "string"
},
"organizationId" : {
"type" : "long"
},
"version" : {
"type" : "long"
}
}
},
"status" : {
"type" : "long"
}
}
},
"version" : {
"type" : "long"
}
}
}
}
}
}
这就是我尝试的方式:(注意original
是BasicInformation
的类型)
client.Map<MyVersion>(x => x
.Properties(p => p.NestedObject<BasicInformation>(s => s.Name(n => n.Original)
.Properties(pp => pp.String(ss => ss.Name(nn => nn.MyCode)
.Index(FieldIndexOption.NotAnalyzed))))));
我似乎无法找到我做错的事情......
附加信息:
MyVersion课程:
public class MyVersion : IMyVersion
{
private int? _myVersionId;
public int Id
{
get { return _myVersionId.HasValue ? _myVersionId.Value : Original.myVersionId; }
set
{
_myVersionId = value;
}
}
public int Version { get; set; }
public int MaxVersion { get; set; }
public BasicInformation Original { get; set; }
[Obsolete("Used only for deserialization")]
public MyVersion()
{
}
internal MyVersion(BasicInformation original, int version, int maxVersion)
{
Original = original;
Version = version;
MaxVersion = maxVersion;
}
public bool IsLatest
{
get
{
return Version == MaxVersion;
}
}
public bool Equals(IMyVersion other)
{
return other != null && Id.Equals(other.Id);
}
}
是的,json是在映射之后。另外,我正在检查测试是否正确。
var mapping = ElasticClient.GetMapping<MyVersion>();
var basicInformationMapping = mapping.Mappings[TEST_INDEX_NAME][0].Mapping.Properties[PropertyNameMarker.Create("original")] as
ObjectMapping;
var myCodeMapping =
basicInformationMapping.Properties[PropertyNameMarker.Create("myCode")] as StringMapping;
Assert.IsTrue(myCodeMapping.Index == FieldIndexOption.NotAnalyzed, "myCode field mapping index should be NotAnalyzed");
更新:
UpdateMapping(client, indexName);
foreach (var myVersion in myVersions.Versions)
{
var version = myVersion;
client.Index(myVersion, i => i.Id(version.Id).Index(indexName));
}