gpt4 book ai didi

elasticsearch - ElasticSearch-将索引字段升级为多字段-新字段为空

转载 作者:行者123 更新时间:2023-12-02 23:33:12 26 4
gpt4 key购买 nike

注意到我在索引字符串字段上进行的排序无法正常工作后,我发现它正在对已分析的字符串进行排序,因此需要“单词袋”,如果我想使其正常运行,则必须对未分析的字符串进行排序。我的计划是使用在这两篇文章中找到的信息,将字符串字段更改为多字段:

https://www.elastic.co/blog/changing-mapping-with-zero-downtime(升级到多字段部分)
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html

使用Sense,我创建了此字段映射

PUT myindex/_mapping/type
{
"properties": {
"Title": {
"type": "string",
"fields": {
"Raw": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}

然后,我尝试使用新创建的字段对搜索结果进行排序。阅读文章后,我已经想到了所有名称变体:
POST myindex/_search
{
"_source" : ["Title","titlemap.Raw","titlemap.Title","titlemap.Title.Raw","Title.Title","Raw","Title.Raw"],
"size": 6,
"query": {
"multi_match": {
"query": "title",
"fields": ["Title^5"
],
"fuzziness": "auto",
"type": "best_fields"
}
},
"sort": {
"Title.Raw": "asc"
}
}

这就是我的回应:
{
"_index": "myindex_2015_11_26_12_22_38",
"_type": "type",
"_id": "1205",
"_score": null,
"_source": {
"Title": "The title of the item"
},
"sort": [
null
]
}

响应中仅显示“标题”字段的值,并且每个结果的排序标准均为空。

我是在做错什么,还是有另一种方法?

最佳答案

重新索引后,索引名称不同,因此将安装默认映射...这可能就是原因。

我建议改用index template,这样您就不必担心何时创建索引了,ES会为您完成。这个想法是用所需的适当映射创建一个模板,然后ES将在需要时创建每个新索引,添加myindex别名并将适当的映射应用于该索引。

curl -XPUT localhost:9200/_template/myindex_template -d '{
"template": "myindex_*",
"settings": {
"number_of_shards": 1
},
"aliases": {
"myindex": {}
},
"mappings": {
"type": {
"properties": {
"Title": {
"type": "string",
"fields": {
"Raw": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
}'

然后,无论何时启动重新索引过程,都会使用正确的映射和正确的别名创建具有新名称的新索引。

关于elasticsearch - ElasticSearch-将索引字段升级为多字段-新字段为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34227700/

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