使用ES 2.3.2并让父母item
和子女user_item_relation
使用以下地址:
"mappings": {
"item": {
"dynamic": "strict",
"properties" : {
"title" : { "type": "string" },
"body" : { "type": "string" },
"source_id" : { "type": "integer" },
"time_order" : { "type": "string" },
"source_type" : { "type": "integer" }
}
},
"user_item_relation": {
"_parent": {"type": "item" },
"properties" : {
"user_id" : { "type": "integer" },
"item_id" : { "type": "integer" },
"source_id" : { "type": "integer" },
"favorite" : { "type": "integer" },
"pending" : { "type": "integer" },
"tags" : { "type": "string" },
"featured" : { "type": "integer" }
}}}}'
我知道我可以更新例如位于父(source_type
)的item
的值为133,以查找与查询匹配的所有文档(title
有单词duros
和孩子(user_item_relation
有user_id = 1234
)使用_update_by_query
脚本。
curl -X POST 'myip:9200/my/_update_by_query' -d'{
"query": {
"bool": {
"must": [
{
"query_string": {
"default_field": "title",
"query": "duros"
}
},
{
"has_child": {
"type": "user_item_relation",
"query": {
"term": {
"user_id": 1234
}}}}]}},
"script" : { "inline" : "ctx._source.source_type = 133"}
}'
但是当我尝试使用相同的查询(ctx._source.favorite = 0
)
curl -X POST 'myip:9200/my/_update_by_query' -d'{
"query": {
"bool": {
"must": [
{
"query_string": {
"default_field": "title",
"query": "duros"
}
},
{
"has_child": {
"type": "user_item_relation",
"query": {
"term": {
"user_id": 1234
}}}}]}},
"script" : { "inline" : "ctx._source.favorite = 0"}
}'
显示以下错误:
{"把":1481," TIMED_OUT":假,"总":1,"更新":0,&# 34;批次":1," version_conflicts":0," noops":0,"重试":0," failu RES":[{"指数":"我""类型":"项目"" ID&#34 ;:" 10""原因" {"类型":" strict_dynamic_mapping_exception"" REA 儿子":"映射设置为严格,动态引入[精选]内 [item]不允许"}," status":400}]}
正如您可以阅读它尝试修改不存在的父(featured
)上的字段item
的值,因为它对孩子而不是在父母身上。
如何更改脚本行,以便将favorite
(儿童user_item_relation
上的)的值设为0
?