elasticsearch 的post put 方式的对比 setting mapping设置
Posted littlevigra
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了elasticsearch 的post put 方式的对比 setting mapping设置相关的知识,希望对你有一定的参考价值。
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
以上是关于elasticsearch 的post put 方式的对比 setting mapping设置的主要内容,如果未能解决你的问题,请参考以下文章
WCF RESTful 应用程序 PUT、POST、DELETE 收到相同的错误:“该方法不允许。”