Я использую ES 5.1
. Мне нужно ввести новый элемент и установить значение по умолчанию этого нового элемента в начальное значение. Требование кажется простым, но почему мы не можем сделать это в ES query
?
Я попытался _update_by_query
, используя сопоставление всех элементов или сопоставление элементов, у которых нет этого нового элемента.
У меня есть элемент "пригласить" в сопоставлении. Я пробовал следующие способы, но не работал:
Структура отображения в индексе "users-prod":
"preferences": {
"properties": {
"invite": {
"type": "boolean"
}
}
}
POST users-prod/user/_update_by_query
{
"script": {
"inline": "ctx._source.preferences.invite = true"
},
"query": {
"match_all": {}
}
}
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"ctx._source.preferences.invite = true",
" ^---- HERE"
],
"script": "ctx._source.preferences.invite = true",
"lang": "painless"
}
],
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"ctx._source.preferences.invite = true",
" ^---- HERE"
],
"script": "ctx._source.preferences.invite = true",
"lang": "painless",
"caused_by": {
"type": "null_pointer_exception",
"reason": null
}
},
"status": 500
}
POST users-prod/user/_update_by_query
{
"query": {
"bool": {
"must_not": [
{
"exists": {
"field": "preferences.invite"
}
}
]
}
},
"script": {
"inline": "ctx._source.preferences.invite = true"
}
}
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"ctx._source.preferences.invite = true",
" ^---- HERE"
],
"script": "ctx._source.preferences.invite = true",
"lang": "painless"
}
],
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"ctx._source.preferences.invite = true",
" ^---- HERE"
],
"script": "ctx._source.preferences.invite = true",
"lang": "painless",
"caused_by": {
"type": "null_pointer_exception",
"reason": null
}
},
"status": 500
}