我是Elasticsearch的新手。我需要使用“analyze”和“not_analyzed”索引创建所有字符串字段。我已经能够为1或2个字段执行此操作,但如果我的文档中有50个字段,我该怎么办呢?我使用以下代码在几个字段上创建这样的索引:
mapping = {
"my_type": {
"properties": {
"random_num": {"type": "string"},
"category": { "type":"multi_field", "fields":{ "category":{ "type":"string", "index":"analyzed" },"untouched":{ "type":"string", "index":"not_analyzed" } } },
"url": {"type": "string"},
"id": {"type": "string"},
"desc": { "type":"multi_field", "fields":{ "desc":{ "type":"string", "index":"analyzed" },"untouched":{ "type":"string", "index":"not_analyzed" } } }
}
}
}
如果有人帮我解决这个问题,我真的很感激。谢谢!
答案 0 :(得分:1)
您可以查看文档here。 使用动态索引模板,您可以添加如下所示的规则并使用相同的规则。 在下面的示例中,如果大小小于256(未进行分析),我已启用了另一个名为raw ONLY的字段。
{
"mappings": {
"my_type": {
"dynamic_templates": [
{
"string_fields": {
"mapping": {
"type": "string",
"fields": {
"raw": {
"index": "not_analyzed",
"ignore_above": 256,
"type": "string"
}
}
},
"match_mapping_type": "string",
"match": "*"
}
}
]
}
}
}