ES命令的学习(一)

发布时间:2023年12月29日

索引

创建索引

创建一个索引,包含2个分片1份副本(settings),指定了2个字段类型(mappings) 。

PUT greeting
{
    "settings" : {
      "number_of_shards" : 2, 
      "number_of_replicas" : 1 
    },
    "mappings" : {
        "_doc" : {
            "properties" : {
                "email" : { "type" : "keyword" },
                "message" : { "type" : "text" }
            }
        }
    }
}

写入索引

POST book/_doc
{
  "email" : "xxxx@qq.com",
  "message" : "hello world"
}

写入索引(指定ID)

POST book/_doc/1
{
  "email" : "xxxx@qq.com",
  "message" : "hello world"
}

Bulk 批量写入

POST greeting/_bulk
{ "index" : { "_type" : "_doc"} }
{ "email" : "xxxx@qq.com","message":"hello1" }
{ "index" : { "_type" : "_doc"} }
{ "email" : "yyyy@qq.com","message":"hello2" }
{ "index" : { "_type" : "_doc"} }
{ "email" : "zzzz@qq.com","message":"hello3" }
{ "index" : { "_type" : "_doc"} }
{ "email" : "aaaa@qq.com","message":"hello4" }

文档

获取单个文档

GET book/_doc/1

获取多个文档

GET /_mget
{
    "docs" : [
        {
            "_index" : "book1",
            "_type" : "_doc",
            "_id" : "1"
        },
        {
            "_index" : "book2",
            "_type" : "_doc",
            "_id" : "2"
        }
    ]
}

来源:ElasticSearch命令大全

文章来源:https://blog.csdn.net/weixin_42592415/article/details/135266488
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。