gpt4 book ai didi

elasticsearch - 在 Elasticsearch 中添加文档时 PUT 与 POST

转载 作者:行者123 更新时间:2023-12-02 22:10:37 24 4
gpt4 key购买 nike

我是 Elasticsearch 的新手,并试图在弹性索引中添加文档。我在这里对 PUT 和 POST 感到困惑,因为它们在以下场景中产生相同的结果:

curl -H "Content-Type: application/json" -XPUT "localhost:9200/products/mobiles/1?pretty" -d"
{
"name": "iPhone 7",
"camera": "12MP",
"storage": "256GB",
"display": "4.7inch",
"battery": "1,960mAh",
"reviews": ["Incredibly happy after having used it for one week", "Best iPhone so far", "Very expensive, stick to Android"]
}
"

对比
curl -H "Content-Type: application/json" -XPOST "localhost:9200/products/mobiles/1?pretty" -d"
{
"name": "iPhone 7",
"camera": "12MP",
"storage": "256GB",
"display": "4.7inch",
"battery": "1,960mAh",
"reviews": ["Incredibly happy after having used it for one week", "Best iPhone so far", "Very expensive, stick to Android"]
}
"

最佳答案

  • POST : 用于实现 id 的自动生成。
  • PUT :当你想指定一个 id 时使用。

  • this

    关于elasticsearch - 在 Elasticsearch 中添加文档时 PUT 与 POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56766688/

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