【ElasticSearch】文档(添加)单个和批量

创建空索引

PUT myindex
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 1
  },
  "mappings": {
    "properties": {
      "name": {
        "type": "keyword",
        "ignore_above": 100
      },
      "age": {
        "type": "integer"
      }
    }
  }
}

 

单个添加

请求

PUT /<target>/_doc/<_id>
POST /<target>/_doc/
PUT /<target>/_create/<_id>
POST /<target>/_create/<_id>

You cannot add new documents to a data stream using the PUT /<target>/_doc/<_id> request format. 
To specify a document ID, use the PUT /<target>/_create/<_id> format instead. See Add documents to a data stream.

1、REST API

文档:https://www.elastic.co/guide/en/elasticsearch/reference/7.13/docs-index_.html

PUT myindex/_create/1
{
  "name": "张三",
  "age": 20
}
PUT myindex/_doc/2
{
  "name": "李四",
  "age": 25
}

2、Java REST Client

 

 

 

批量添加

1、REST API

2、Java REST Client

posted @ 2023-11-11 10:44  翠微  阅读(93)  评论(0编辑  收藏  举报