ES命令的学习(一)

简单命令

  • 索引
    • 创建索引
    • 写入索引
    • 写入索引(指定ID)
    • Bulk 批量写入
  • 文档
    • 获取单个文档
    • 获取多个文档

索引

创建索引

创建一个索引,包含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" : "[email protected]",
  "message" : "hello world"
}

写入索引(指定ID)

POST book/_doc/1
{
  "email" : "[email protected]",
  "message" : "hello world"
}

Bulk 批量写入

POST greeting/_bulk
{ "index" : { "_type" : "_doc"} }
{ "email" : "[email protected]","message":"hello1" }
{ "index" : { "_type" : "_doc"} }
{ "email" : "[email protected]","message":"hello2" }
{ "index" : { "_type" : "_doc"} }
{ "email" : "[email protected]","message":"hello3" }
{ "index" : { "_type" : "_doc"} }
{ "email" : "[email protected]","message":"hello4" }

文档

获取单个文档

GET book/_doc/1

获取多个文档

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

来源:ElasticSearch命令大全

你可能感兴趣的:(elasticsearch,学习,数据库)