我是Elastic Search / NEST的新手。目前我正在尝试将以下类映射到:
[ElasticType(
Name = "zData",
SearchAnalyzer = "standard",
IndexAnalyzer = "standard",
DateDetection = false,
NumericDetection = true
)]
public class zData {
[ElasticProperty(Type = FieldType.string_type)]
public String zName {
get;
set;
}
[ElasticProperty(Type = FieldType.string_type)]
public String zType {
get;
set;
}
[ElasticProperty(Type = FieldType.nested)]
public List<zData> Items {
get;
set;
}
[ElasticProperty(Type = FieldType.string_type)]
public String Value {
get;
set;
}
}
首先,我尝试自动完全映射它。后来我尝试自己创建一个Mapping,它大部分就像是github上测试项目中的一个:
var r = IndexClient.MapFluent<zData>(z => z
.TypeName("zData")
.IndexNames("testdata")
.IgnoreConflicts()
.IndexAnalyzer("standard")
.SearchAnalyzer("standard")
.DateDetection(false)
.NumericDetection(false)
.MapFromAttributes()
.DisableAllField(false)
.DisableIndexField(false)
.DisableSizeField(false)
.Dynamic()
.Enabled()
.Path("full")
.Properties(props => props
.Object<zData>(s => s
.Name(p => p.Items.First())
.Dynamic()
.Enabled()
.IncludeInAll()
.MapFromAttributes()
.Path("full")
.Properties(pprops => pprops
.String(ps => ps.Name(p => p.zName).Index(FieldIndexOption.not_analyzed))
.String(ps => ps.Name(p => p.zType).Index(FieldIndexOption.not_analyzed))
.String(ps => ps.Name(p => p.Value).Index(FieldIndexOption.not_analyzed))
)
)
.NestedObject<zData>(s => s
.Name(p => p.Items.First())
.Dynamic()
.Enabled()
.IncludeInAll()
.IncludeInParent()
.IncludeInRoot()
.MapFromAttributes()
.Path("full")
.Properties(pprops => pprops
.String(ps => ps.Name(p => p.zName).Index(FieldIndexOption.not_analyzed))
.String(ps => ps.Name(p => p.zType).Index(FieldIndexOption.not_analyzed))
.String(ps => ps.Name(p => p.Value).Index(FieldIndexOption.not_analyzed))
)
)
)
);
我不确定这种映射对我的情况是否方便。我得到的例外情况如下:
Process is terminated due to StackOverflowException
关闭程序后,我收到来自Visual Studio的消息,mscorlib.dll中发生了异常。
我知道问题是因为无休止的循环。 zData对象可以有一个zData列表,每个列表都包含一个zData列表,依此类推。但是,是否有任何命令告诉NEST不要比第一个列表更深入?也许有人知道zData的另一种结构,它与当前一样灵活,但是更多的是保存到地图?
Edit1:新映射
var mapping = IndexClient.MapFluent<zData>(m => m
.IgnoreConflicts()
.Dynamic()
.Enabled()
.IncludeInAll()
.DisableAllField(false)
.DisableIndexField(false)
.DisableSizeField(false)
.Path("full")
.AnalyzerField(a => a
.SetPath(p => p.zName)
.SetIndexed()
)
.TypeField(t => t
.SetIndexed()
.SetStored()
)
.Properties(p => p
.String(s => s
.Name(n => n.zName)
.IndexName("name")
.IncludeInAll()
.Index(FieldIndexOption.analyzed)
.SearchAnalyzer("standard")
.Store()
)
.String(s => s
.Name(n => n.zType)
.IndexName("ztype")
.IncludeInAll()
.Index(FieldIndexOption.analyzed)
.SearchAnalyzer("standard")
.Store()
)
.String(s => s
.Name(n => n.Value)
.IndexName("value")
.IncludeInAll()
.Index(FieldIndexOption.analyzed)
.SearchAnalyzer("standard")
.Store()
)
.NestedObject<zData>(z => z
.Name(n => n.Items.First())
.Dynamic()
.Enabled()
.IncludeInAll()
.Path("full")
.Properties(pp => pp
.String(ps => ps
.Name(na => na.zName)
.Index(FieldIndexOption.not_analyzed)
)
)
)
)
);
答案 0 :(得分:0)
MapFromAttributes()
递归遍历完整的对象图,默认情况下没有recursionLimit。
幸运的是,你可以用MapFromAttributes(maxRecursion:1)
给它一个。