Docs/ELK/es学习记录05-要点儿.md
2022-10-18 16:59:37 +08:00

16 lines
817 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

### 创建新文档
_index 、 _type 和 _id 的组合可以唯一标识一个文档。所以,确保创建一个新文档的最简单办法是,使用索引请求的 POST 形式让 Elasticsearch 自动生成唯一 _id
如果已经有自己的 _id ,那么我们必须告诉 Elasticsearch ,只有在相同的 _index 、 _type 和 _id 不存在时才接受我们的索引请求。这里有两种方式,他们做的实际是相同的事情。使用哪种,取决于哪种使用起来更方便。
第一种使用op_type查询-字符串参数
```
PUT /website/blog/123?op_type=create
{ ... }
```
第二种,在 URL 末端使用 /_create :
```
PUT /website/blog/123/_create
{ ... }
```
如果具有相同的 _index 、 _type 和 _id 的文档已经存在Elasticsearch 将会返回 409 Conflict 响应码