我正在尝试更改分析器以获取索引的映射。我理解如何为简单的Text
类型属性执行此操作,但在.NET中,我使用NEST的AutoMap()函数创建映射的类是Dictionary<object, object>
类型,它创建索引映射看起来像这样:
"attributes": {
"properties": {
"comparer": {
"type": "object"
},
"count": {
"type": "integer"
},
"item": {
"type": "object"
},
"keys": {
"properties": {
"count": {
"type": "integer"
}
}
},
"values": {
"properties": {
"count": {
"type": "integer"
}
}
}
}
},
当尝试更改上述映射中某个字段的分析器时,我收到以下消息:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "mapper [attributes.Title] of different type, current_type [text], merged_type [ObjectMapper]"
}
],
"type": "illegal_argument_exception",
"reason": "mapper [attributes.Title] of different type, current_type [text], merged_type [ObjectMapper]"
},
"status": 400
}
我从错误消息中假设我不能将分析器放在像Dictionary<object, object>
那样通用的东西上,但我需要找到一种可行的方法吗? (假设有可能)
答案 0 :(得分:0)
以下NEST auto&amp;手动流畅的代码为我解决了上述问题。我相信Elastic Search试图理解导致它永远不会创建索引的Dictionary<object, object>
存在问题。使用Object<object>
做了诀窍:
elasticClient.CreateIndex("YOURINDEX", i => i
.Mappings(ms => ms
.Map<YOURTYPE>(m => m
.AutoMap()
.Properties(props => props
.Object<object>(o => o
.Name(x => x.Attributes)
.Properties(pprops => pprops
.Text(ps => ps
.Name(AttributeType.Title.ToString().ToLower())
.Analyzer("whitespace")
.Fielddata(true)
.Fields(f => f
.Keyword(k => k
.Name("keyword")
)
)
)
)
)
)
)
)
);