I'm trying to map MyCode
property in my object (posted down) as NotAnalyzed
using fluent.
I've already reviewed: Creating an index Nest and 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"
}
}
}
}
}
}
This is how I tried: (do note original
is type of 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))))));
I can't seem to find what i'm doing wrong...
ADDITIONAL INFO:
MyVersion class:
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);
}
}
Yes that json is after mapping. Also, I'm checking if mapping is correct with a test.
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");
UPDATE:
UpdateMapping(client, indexName);
foreach (var myVersion in myVersions.Versions)
{
var version = myVersion;
client.Index(myVersion, i => i.Id(version.Id).Index(indexName));
}