【问题标题】:How do you add an object to an array using scripts in ElasticSearch?如何使用 ElasticSearch 中的脚本将对象添加到数组中?
【发布时间】:2017-08-31 05:00:20
【问题描述】:

我正在尝试将一个项目添加到我的一个 Elastic Search 文档中的数组中。我可以为简单的项目(例如字符串)执行此操作,但现在无法添加对象。这是我当前的代码:

POST /user_profiles/user_profile/12345/_update
{
    "script" : {
        "inline": "ctx._source.searches.add(params.search)",
        "lang": "painless",
        "params" : {
            "search" : {
                "test": "test2"
            }
        }
    }
}

我收到以下错误:

{
   "error": {
      "root_cause": [
         {
            "type": "mapper_parsing_exception",
            "reason": "failed to parse [searches]"
         }
      ],
      "type": "mapper_parsing_exception",
      "reason": "failed to parse [searches]",
      "caused_by": {
         "type": "illegal_state_exception",
         "reason": "Can't get text on a START_OBJECT at 1:29"
      }
   },
   "status": 400
}

【问题讨论】:

  • 你能展示一下/user_profiles/user_profile/12345在你更新之前的样子吗?
  • 我发现了问题。它与查询本身无关。问题是索引的映射不包含附加字段。

标签: elasticsearch elasticsearch-5 elasticsearch-painless


【解决方案1】:

我发现了问题。它与查询本身无关。问题是索引的映射不包含附加字段。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-13
    • 1970-01-01
    • 1970-01-01
    • 2020-02-22
    相关资源
    最近更新 更多