elasticsearch 将字段设置为elasticsearch 1.7中索引下的所有(未来)类型中未分析的字段
我有一个包含很多类型的索引,新类型的创建不受我的控制。我知道数据结构非常可靠,但我事先不知道类型的名称 我想将一些字段设置为未分析,而有些字段应进行分析。有什么办法可以做到这一点吗?有办法。既然你提到了elasticsearch 将字段设置为elasticsearch 1.7中索引下的所有(未来)类型中未分析的字段,elasticsearch,mapping,elasticsearch,Mapping,我有一个包含很多类型的索引,新类型的创建不受我的控制。我知道数据结构非常可靠,但我事先不知道类型的名称 我想将一些字段设置为未分析,而有些字段应进行分析。有什么办法可以做到这一点吗?有办法。既然你提到了analysistedvsnot\u analysisted我想你说的是string字段 其思想是更新索引和映射,以便为字符串字段包含动态模板: PUT my_index { "mappings": { "my_type": { "dynamic_templates": [
analysisted
vsnot\u analysisted
我想你说的是string
字段
其思想是更新索引和映射,以便为字符串字段包含动态模板:
PUT my_index
{
"mappings": {
"my_type": {
"dynamic_templates": [ <--- include this section in your existing mapping
{
"analyzed": {
"match_mapping_type": "string",
"match": "field1",
"mapping": {
"type": "string"
}
}
},
{
"not_analyzed": {
"match_mapping_type": "string",
"match": "field2",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}
]
}
}
}
我还想补充Val的优秀回答,您可能希望将这些动态模板添加到索引的
\u default\u
映射中,因为您提到您事先不知道这些类型。例如:
PUT /my_index/_mapping/_default_
{
"dynamic_templates": [
{
"analyzed": {
"match_mapping_type": "string",
"match": "*_text",
"mapping": {
"type": "string"
}
}
},
{
"not_analyzed": {
"match_mapping_type": "string",
"match": "*_key",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}
]
}
有了它,您可以向索引添加任意类型,并且将分析添加到新类型的文档中以“\u text”结尾的任何字段。将不分析以“\u key”结尾的任何字段。你可以阅读更多关于这本书的内容
PUT /my_index/_mapping/_default_
{
"dynamic_templates": [
{
"analyzed": {
"match_mapping_type": "string",
"match": "*_text",
"mapping": {
"type": "string"
}
}
},
{
"not_analyzed": {
"match_mapping_type": "string",
"match": "*_key",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}
]
}