gpt4 book ai didi

spring-boot - 在ElasticSearch中不使用脚本即可追加字符串

转载 作者:行者123 更新时间:2023-12-03 00:37:12 24 4
gpt4 key购买 nike

我需要在不使用脚本的情况下在文档的现有字段中附加字符串。
我的文档有一个字段“Field1”,当前具有value1。我想通过将value2附加到“Field1”来更新文档,以便将该字段的值更新为“value1value2”。
使用脚本可以很容易地做到这一点。但是,还有其他选择可以实现这一目标。我也只想使用update / update_by_query语句。

最佳答案

正如@joe建议的那样,您需要在摄取时执行此操作,但是,您可以创建一个管道作为建议。我使用附加处理器和连接处理器进行了本地测试。首先,我附加了field1的值和field2的值,然后在以名称append_fields创建的数组上使用联接处理器。
我在索引“append_index”中摄取了以下值,
“field1”:“value1”,
“field2”:“value2”
“field1”:“value10”,
“field2”:“value11”
我建议您创建以下管道(append_values),然后使用_update_by_query运行它:

PUT _ingest/pipeline/append_values
{
"processors": [
{
"append": {
"field": "append_fields",
"value": [
"{{field1}}",
"{{field2}}"
]
}
},
{
"join": {
"field": "append_fields",
"separator": ""
}
}
]
}
要在 _update__by_query中使用管道,请使用以下命令: POST append_index/_update_by_query?pipeline=append_values响应将是:
"hits" : [
{
"_index" : "append_index",
"_type" : "_doc",
"_id" : "_9ovaHQBsTCl1BZv7qhZ",
"_score" : 1.0,
"_source" : {
"field1" : "value1",
"append_fields" : "value1value2",
"field2" : "value2"
}
},
{
"_index" : "append_index",
"_type" : "_doc",
"_id" : "AdovaHQBsTCl1BZv9ak1",
"_score" : 1.0,
"_source" : {
"field1" : "value10",
"append_fields" : "value10value11",
"field2" : "value11"
}
}
]
链接:
https://www.elastic.co/guide/en/elasticsearch/reference/7.9/append-processor.html
https://www.elastic.co/guide/en/elasticsearch/reference/7.9/join-processor.html
https://www.elastic.co/guide/en/elasticsearch/reference/7.9/pipeline.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html
希望我的建议有帮助:)
如果需要帮助以了解附加处理器的功能,这是不使用联接处理器执行附加处理器的输出:
"hits" : [
{
"_index" : "append_index",
"_type" : "_doc",
"_id" : "G9o9aHQBsTCl1BZvMcv6",
"_score" : 1.0,
"_source" : {
"field1" : "value1",
"append_fields" : [
"value1",
"value2"
],
"field2" : "value2"
}
},
{
"_index" : "append_index",
"_type" : "_doc",
"_id" : "edo9aHQBsTCl1BZvP8vT",
"_score" : 1.0,
"_source" : {
"field1" : "value10",
"append_fields" : [
"value10",
"value11"
],
"field2" : "value11"
}
}
]

关于spring-boot - 在ElasticSearch中不使用脚本即可追加字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63771364/

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