我已经使用以下设置和映射创建了索引:
PUT test
{
"settings": {
"number_of_shards": 2,
"number_of_replicas": 1
},
"mappings": {
"documents": {
"properties": {
"title": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
},
"url": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
},
"tags": {
"type": "keyword"
}
}
}
}
}在上面的映射中,我将标签声明为添加了10个文档的match.and的类型关键字,例如:
PUT test/documents/1
{
"title":"John",
"url":"/john",
"tags":["name question","how"]
}但我想为标签添加多字段支持,以支持部分标签匹配,因此我更新了索引映射,如下所示:
PUT test/documents/_mapping
{
"properties": {
"title": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
},
"url": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
},
"tags": {
"type": "keyword",
"fields": {
"raw": {
"type": "text"
}
}
}
}
}这是升级索引映射的正确方式吗?我的标签现在可以支持部分匹配了吗?请帮我解决这个问题
发布于 2018-07-23 16:56:45
是。这就是更新该字段的方法。尽管我没有使用raw作为子字段的名称。将raw作为text类型并不常见。例如,我会将其命名为fulltext。
无论如何,即使您更新了映射,也必须对所有文档重新建立索引。
Update by Query将做到这一点:
curl -X POST "localhost:9200/test/_update_by_query?conflicts=proceed"顺便说一下(与您的问题无关),我将使用_doc作为类型名,这样您就可以更好地为将来删除类型做好准备。
https://stackoverflow.com/questions/51474413
复制相似问题