gpt4 book ai didi

elasticsearch - Elasticsearch将值追加到Array字段

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

我正在使用Elasticsearch v2.1.1。我已经用关键字,收藏等一些字段在其中索引了数据集。

我的样本索引数据集如下:

{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 103,
"max_score": 1,
"hits": [
{
"_index": "pibtest1",
"_type": "SearchTech",
"_id": "http://www.searchtechnologies.com/images/solutions/candidate-search-match-dashboard.PNG",
"_score": 1,
"_source": {
"Collection": "default_collection",
"keywords": "keywords-NOT-PROVIDED"
}
}
}
}

现在,我要将逗号分隔的值附加到“集合”字段。

例如:“Collection”:[“default_collection”,“wiki_collection”]

现在,“收集”字段的类型为“字符串”。我相信Collection字段必须为此类型的数组。因此,在对ES中的数据建立索引之前,是否应该创建一个数组类型映射?如果是,我该怎么办?
我曾尝试如下创建映射(在对数据建立索引之前),但这种方法不起作用,并给了我一个错误。
PUT pibtest1
{
"mappings":{
"SearchTech": {
"properties": {
"Collection" :{
"type": "array",
"index": "analyzed"
}
}
}
}
}

错误:
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "No handler for type [array] declared on field [Collection]"
}
],
"type": "mapper_parsing_exception",
"reason": "Failed to parse mapping [SearchTech]: No handler for type [array] declared on field [Collection]",
"caused_by": {
"type": "mapper_parsing_exception",
"reason": "No handler for type [array] declared on field [Collection]"
}
},
"status": 400
}

我该如何使用_update API?我读到更新api将用新值替换现有值,但是我需要将该值附加到数组中。
我想搜索查询并更新结果的“收集”字段。谢谢。

我发现了类似的帖子: Append to an existing elasticsearch array field using python

最佳答案

您无需更改任何内容。在Elasticsearch中,每个字段可以处理一个值或值数组:

      POST index/type/id
{
"Collection": "default_collection",
"keywords": "keywords-NOT-PROVIDED"
}


      POST index/type/id
{
"Collection": ["default_collection", "extra value"],
"keywords": "keywords-NOT-PROVIDED"
}

两者都使用相同的映射

关于elasticsearch - Elasticsearch将值追加到Array字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36921691/

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