gpt4 book ai didi

elasticsearch - 是否可以通过查询更新嵌套字段?

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

我正在使用按查询更新插件( https://github.com/yakaz/elasticsearch-action-updatebyquery/ )按查询更新文档。
就我而言,文档中有嵌套字段,映射是这样的:

"mappings": {
"mytype": {
"properties": {
"Myfield1": {
"type": "nested",
"properties": {
"field1": {
"type": "string"
},
"field2": {
"type": "long"
}
}
},
"Title": {
"type": "string"
}
}
}
}

然后我想通过以下请求通过查询更新嵌套字段 Myfield1:

但不幸的是,它不起作用。
{
"query": {
"match": {
"Title": "elasticsearch"
}
},
"script": "ctx._source.Myfield1 = [{'nestfield1':'foo blabla...','nestfield2':100},{'nestfield1':'abc...','nestfield2':200}]"
}

按查询更新是否支持嵌套对象?

顺便说一句:还有其他方法可以通过查询更新文档吗?

查询插件更新是唯一的选择吗?

最佳答案

此示例使用 _update_by_query

POST indexname/type/_update_by_query
{
"query": {
"match": {
"Title": "elasticsearch"
}
},
"script": {
"source": "ctx._source.Myfield1= params.mifieldAsParam",
"params": {
"mifieldAsParam": [
{
"nestfield1": "foo blabla...",
"nestfield2": 100
},
{
"nestfield1": "abc...",
"nestfield2": 200
}
]
},
"lang": "painless"
}
}

关于elasticsearch - 是否可以通过查询更新嵌套字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29961075/

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