gpt4 book ai didi

elasticsearch - 如何更新 ElasticSearch 索引映射并向其中添加多字段?

转载 作者:行者123 更新时间:2023-12-02 22:12:13 24 4
gpt4 key购买 nike

我已经使用以下设置和映射创建了索引:

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 个文档,例如:

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"
}
}
}
}
}

这是更新索引映射的正确方法吗?我的标签现在可以支持部分匹配吗?请帮我解决这个问题

最佳答案

是的。这就是更新该字段的方式。尽管我不会使用 raw 作为子字段的名称。将 raw 作为 text 类型并不常见。例如,我将其命名为 fulltext

无论如何,即使您更新了映射,您也必须重新索引所有文档。

Update by Query会这样做:

curl -X POST "localhost:9200/test/_update_by_query?conflicts=proceed"

顺便说一句(与您的问题无关)我将使用 _doc 作为类型名称,这样您就可以为将来删除类型做好更充分的准备。

关于elasticsearch - 如何更新 ElasticSearch 索引映射并向其中添加多字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51474413/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com