【问题标题】:ElasticSearch: POST update without Index, Type and IdElasticSearch:没有索引、类型和 ID 的 POST 更新
【发布时间】:2018-06-25 16:23:36
【问题描述】:

这是我在 elasticsearch 中的一份文档:

{
            "_index": "2017-10-21",
            "_type": "cat",
            "_id": "14",
            "_score": 2.2335923,
            "_source": {
                "name": "Biscuit",
                "breed": "Persian",
                "age": "3"
            }
}

我知道可以通过POST update 向现有文档添加新字段:

POST [index] / [type] / [id] / _update 

例如,如果我想在我的文档中添加一个新字段“hairy”:

POST 2017-10-21 / cat / 14 / _update

{
     "script" : "ctx._source.hairy = 'yes'"
}

我会得到这个结果:

{
            "_index": "2017-10-21",
            "_type": "cat",
            "_id": "14",
            "_source": {
                "name": "Biscuit",
                "breed": "Persian",
                "age": "3",
                "hairy": "yes"
            }
}

但是,我想为我的所有文档添加一个新字段,无论它们的索引、类型或 ID 是什么。不幸的是,即使经过数小时的研究,我也没有找到一种方法来在不使用索引、类型或 id 的情况下执行POST update

所以,我的问题是:这有可能吗?如果不是,还有其他方法可以做我想做的事吗?

提前感谢您提供的任何帮助!

【问题讨论】:

标签: elasticsearch post


【解决方案1】:

我终于找到了解决办法!

我需要使用POST update_by_query 而不是POST update

POST * / _update_by_query
{
    "script" : {
        "inline": "ctx._source.hairy = 'yes'"
    }
}

星号表示您要选择所有现有索引/索引

【讨论】:

    猜你喜欢
    • 2017-12-25
    • 2023-04-08
    • 2020-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-29
    相关资源
    最近更新 更多