我正在映射传递文档中的所有字段,但偶尔弹性搜索的动态字段映射类型检测会为包含纯文本的字段选择非常严格的类型(如long
)。这似乎是基于包含该字段的ES收到的初始文档。例如:
文件1:
{
"a": 1,
"b": "foo",
"c": {
"nested": 5.5
}
}
文件2:
{
"a": "plain text",
"b": "bar",
"c": {
"nested": "plain text again"
}
}
我可以定义一个索引模板,默认情况下所有值都被索引为text
,如果我明确要这样做,那么只能将其作为其他类型索引吗?
Elasticsearch允许自定义动态映射规则。例如,您可以定义将long
映射到text
的规则:
{
"mappings": {
"dynamic_templates": [
{
"long_to_text": {
"match_mapping_type": "long",
"mapping": {
"type": "text"
}
}
}
]
}
更多细节可以在文档中找到:https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html