Dictionary 字典的嵌套映射<;字符串,列表<;字符串>&燃气轮机;
我有一个班,成员之一是Dictionary 字典的嵌套映射<;字符串,列表<;字符串>&燃气轮机;,dictionary,
elasticsearch,mapping,nest,Dictionary,
elasticsearch,Mapping,Nest,我有一个班,成员之一是字典。我可以使用automap插入数据,但无法使用字典中的键和/或值查询文档。如果使用匹配查询,它将返回索引中的所有内容。我尝试使用术语、嵌套/非嵌套查询和QueryString查询,但它们都不会返回任何文档 class ESSchema { [String(Index = FieldIndexOption.NotAnalyzed, Store = false)] public string Machine { get; set; } [Strin
字典。我可以使用automap插入数据,但无法使用字典中的键和/或值查询文档。如果使用匹配查询,它将返回索引中的所有内容。我尝试使用术语、嵌套/非嵌套查询和QueryString查询,但它们都不会返回任何文档
class ESSchema
{
[String(Index = FieldIndexOption.NotAnalyzed, Store = false)]
public string Machine { get; set; }
[String(Index = FieldIndexOption.NotAnalyzed, Store = false)]
public string Filename { get; set; }
[Number(NumberType.Long, Store = false)]
public long BatchNumber { get; set; }
[String(Index = FieldIndexOption.NotAnalyzed, Store = false)]
public string Environment { get; set; } = null;
[Nested]
//[Object(Store = false)]
public Dictionary<string, List<string>> KeysValues { get; set; }
}
自动映射时,对于字典
属性,字典的公共属性最终会被映射,这是不可取的
有几种方法可以控制这种情况
1.将maxRecursion的-1
传递到AutoMap()
2.通过fluent映射覆盖控制映射
client.Map<ESSchema>(m => m
.AutoMap()
.Properties(p => p
.Object<Dictionary<string, List<string>>>(o => o
.Name(n => n.KeysValues)
.Store(false)
)
)
);
client.Map(m=>m
.AutoMap()
.Properties(p=>p
.Object(o=>o
.Name(n=>n.KeysValues)
.Store(假)
)
)
);
使用.Properties()
将覆盖自动映射中的任何推断映射。我对您的问题进行了一些编辑。你应该进一步添加一个实际问题——到目前为止,这只是一个问题陈述,让读者猜测你具体想要什么。
class ESSchema
{
[String(Index = FieldIndexOption.NotAnalyzed, Store = false)]
public string Machine { get; set; }
[String(Index = FieldIndexOption.NotAnalyzed, Store = false)]
public string Filename { get; set; }
[Number(NumberType.Long, Store = false)]
public long BatchNumber { get; set; }
[String(Index = FieldIndexOption.NotAnalyzed, Store = false)]
public string Environment { get; set; } = null;
[Object(Store = false)]
public Dictionary<string, List<string>> KeysValues { get; set; }
}
client.Map<ESSchema>(m => m
.AutoMap(-1)
);
{
"properties": {
"machine": {
"type": "string",
"store": false,
"index": "not_analyzed"
},
"filename": {
"type": "string",
"store": false,
"index": "not_analyzed"
},
"batchNumber": {
"type": "long",
"store": false
},
"environment": {
"type": "string",
"store": false,
"index": "not_analyzed"
},
"keysValues": {
"type": "object",
"store": false,
"properties": {}
}
}
}
client.Map<ESSchema>(m => m
.AutoMap()
.Properties(p => p
.Object<Dictionary<string, List<string>>>(o => o
.Name(n => n.KeysValues)
.Store(false)
)
)
);