elasticsearch 的post put 方式的对比 setting mapping设置 - 添加查询数据 + elasticsearch 动态模板

1.POST和PUT都可以用于创建

2.PUT是幂等方法,POST不是。所以post用户更新,put用于新增比较合适。 

参考:https://yq.aliyun.com/articles/366099

https://www.bbsmax.com/A/xl56bqb15r/    curl -XGET http://192.168.79.131:9200/shb01/_settings?pretty  curl -XPUT http://192.168.79.131:9200/shb03-d'{"settings":{"number_of_shards":4,"number_of_replicas":2}}'

----------------------------------------------------------------------------------------------------------------------

1.post

复制代码
curl -XPOST http://192.168.1.49:9200/test/user/1  \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json'  -d '{"name" : "john" }'            ==>指定id
----------------------------------------------------

curl -XPOST http://192.168.1.49:9200/test/user/11 \
-H 'cache-control: no-cache' \
-H 'content-type: application/json'  -d '{"name" : "john" }'

非幂等性,可以用来修改记录
----------------------------------------------------
 curl -XPOST http://192.168.1.49:9200/test/user  \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json'  -d '{"name" : "john"}'
不指定id,自动生成
复制代码

2.put

curl -XPUT http://192.168.1.49:9200/test/user/22/_create    -H 'cache-control: no-cache'   -H 'content-type: application/json{"name" : "john" }' 指定id
------------------------------------------------------幂等性,不能重复操作
curl -XPUT http://192.168.1.49:9200/test/user/22/_create    -H 'cache-control: no-cache'   -H 'content-type: application/json{"name" : "john222" }'
version conflict, document already exists

 

posted @   littlevigra  阅读(593)  评论(1编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App
历史上的今天:
2018-11-04 优化ansible速度
2018-11-04 ansible 变量定义和引用 sudo 执行命令
2017-11-04 x509: certificate signed by unknown authority harbor 架构图
2017-11-04 harbor Configuring Harbor with HTTPS Access
点击右上角即可分享
微信分享提示