简体   繁体   English

如何通过URL(http)创建弹性搜索文档文档

[英]How to create a elasticsearch document document via URL(http)

I am new to elasticsearch and trying to find a way to create a document from url(http-API). 我是elasticsearch的新手,并试图找到一种从url(http-API)创建文档的方法。 I have tried below given options but none of them worked. 我尝试过以下给出的选项,但没有一个有效。

    http://Myserver:9200/dilbert/user/3 -d '{ "name" : "Praveena" }
    http://Myserver:9200/dilbert/user/3{ "name" : "Praveena" }
    http://Myserver:9200/dilbert/user/3?pretty _create name=Praveena

I expect this to add a record. 我希望这会增加一条记录。 Here dilbert is Index name. 这里dilbert是索引名称。 user is type & 3 is id. user是type&3是id。 This index only contains a single element called name. 此索引仅包含名为name的单个元素。

First option should work, but you must explicitly set request type to PUT . 第一个选项应该有效,但您必须将请求类型显式设置为PUT

It seems to me that you use curl to insert data. 在我看来,你使用curl来插入数据。 If you send data to server with -d option, curl issues the POST request by default. 如果使用-d选项将数据发送到服务器,则curl默认发出POST请求。 But you specify id of document in URL, so Elasticsearch waits for PUT request (see official documentation ). 但是您在URL中指定了文档的ID,因此Elasticsearch会等待PUT请求(请参阅官方文档 )。 You can use POST requests only in case of automatic ID generation . 您只能在自动ID生成的情况下使用POST请求。

So your request may look as follows: 因此,您的请求可能如下所示:

curl -X PUT http://Myserver:9200/dilbert/user/3 -d '{ "name" : "Praveena" }'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM