hagezhou

Elasticsearch PUT 与 XPUT 差异问题

  •  
  •   hagezhou · Aug 18, 2017 · 7978 views
    This topic created in 3219 days ago, the information mentioned may be changed or developed.

    使用中发现,用 curl -XPUT 一个数据必须加上 id,不然会报错 No handler found for uri [/megacorp/employee/] and method [PUT]

    但是如果用 curl -PUT 则不用 id 也可以自动生成 id,效果和 POST 一样 这是为什么呢?

    5 replies    2017-08-18 16:55:14 +08:00
    hcymk2
        1
    hcymk2  
       Aug 18, 2017
    curl -PUT 这个 curl 会忽略-PUT 的,没有这种写法,当作 get 请求, curl -XPUT 就是一个 PUT 请求
    你可以加个-v 看下
    hagezhou
        2
    hagezhou  
    OP
       Aug 18, 2017
    @hcymk2 -v 的输出
    * Hostname was NOT found in DNS cache
    * Trying 192.168.200.138...
    * Connected to 192.168.200.138 (192.168.200.138) port 9200 (#0)
    > POST /megacorp/employee/ HTTP/1.1
    > User-Agent: curl/7.35.0
    > Host: 192.168.200.138:9200
    > Accept: */*
    > Content-Length: 202
    > Content-Type: application/x-www-form-urlencoded
    >
    * upload completely sent off: 202 out of 202 bytes
    < HTTP/1.1 201 Created

    看起来确实被忽略了,而且实际上是 POST ?
    hagezhou
        3
    hagezhou  
    OP
       Aug 18, 2017
    @hcymk2 XPUT 的-v 确实就是 PUT,看来 curl -PUT 实际上是 POST
    hcymk2
        4
    hcymk2  
       Aug 18, 2017
    加了-d 的吧 当表单提交了 application/x-www-form-urlencoded
    crystom
        5
    crystom  
       Aug 18, 2017
    这个是 curl 的命令特点,和 es 没关系
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3974 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 57ms · UTC 10:15 · PVG 18:15 · LAX 03:15 · JFK 06:15
    ♥ Do have faith in what you're doing.