博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
elasticsearch 命令行最常用的几个操作
阅读量:4229 次
发布时间:2019-05-26

本文共 11641 字,大约阅读时间需要 38 分钟。

查看所有索引

[looking@master ~]$ curl localhost:9200/_cat/indices?vhealth status index    uuid                   pri rep docs.count docs.deleted store.size pri.store.sizeyellow open   website  svdjlzy2TfCQFLHcKWhjRw   1   1          2            0      8.9kb          8.9kbyellow open   bank     E-6sCm3iRRqSweO9L5nWow   1   1       1000            0    414.3kb        414.3kbyellow open   megacorp rzaxRxNTRTyF3YsKlrjxxA   1   1          2            0      6.4kb          6.4kbyellow open   blogs    qfnun_91RI2O1lgTjnBmCQ   3   1          0            0       849b           849b

 查看索引结构

[looking@master ~]$ curl localhost:9200/megacorp/_mapping?pretty{  "megacorp" : {    "mappings" : {      "properties" : {        "about" : {          "type" : "text",          "fields" : {            "keyword" : {              "type" : "keyword",              "ignore_above" : 256            }          }        },        "age" : {          "type" : "long"        },        "first_name" : {          "type" : "text",          "fields" : {            "keyword" : {              "type" : "keyword",              "ignore_above" : 256            }          }        },        "interests" : {          "type" : "text",          "fields" : {            "keyword" : {              "type" : "keyword",              "ignore_above" : 256            }          },          "fielddata" : true        },        "last_name" : {          "type" : "text",          "fields" : {            "keyword" : {              "type" : "keyword",              "ignore_above" : 256            }          }        },        "properties" : {          "properties" : {            "interests" : {              "properties" : {                "fielddata" : {                  "type" : "boolean"                },                "type" : {                  "type" : "text",                  "fields" : {                    "keyword" : {                      "type" : "keyword",                      "ignore_above" : 256                    }                  }                }              }            }          }        }      }    }  }}

所有索引别名

[looking@master ~]$ curl localhost:9200/_alias?pretty{  "website" : {    "aliases" : { }  },  "bank" : {    "aliases" : {      "banks" : { }    }  },  "megacorp" : {    "aliases" : { }  },  "blogs" : {    "aliases" : { }  }}

查看索引别名

[looking@master ~]$ curl -XGET localhost:9200/blogs/_alias/*?pretty{  "blogs" : {    "aliases" : {      "blogs_alias" : { }    }  }}

查看别名索引

[looking@master ~]$ curl -XGET localhost:9200/*/_alias/blogs_alias?pretty{  "blogs" : {    "aliases" : {      "blogs_alias" : { }    }  }}

添加索引别名

[looking@master ~]$ curl -XPOST 'localhost:9200/_aliases?pretty' -H 'Content-Type: application/json' -d '{    "actions": [        {"add": {"index": "bank", "alias": "banks"}}    ]}'{  "acknowledged" : true}

删除索引别名

[looking@master ~]$ curl -XPOST 'localhost:9200/_aliases?pretty' -H 'Content-Type: application/json' -d '> {>   "actions": [>       {"remove": {"index": "bank", "alias": "banks"}}>   ]> }> '{  "acknowledged" : true}

修改索引别名

[looking@master ~]$ curl localhost:9200/bank/_alias?pretty{  "bank" : {    "aliases" : {      "banks" : { }    }  }}[looking@master ~]$ curl -XPOST 'localhost:9200/_aliases?pretty' -H 'Content-Type: application/json' -d '> {>   "actions": [>       {"remove": {"index": "bank", "alias": "banks"}},>       {"add": {"index": "bank", "alias": "bank_bak"}}>   ]> }> '{  "acknowledged" : true}[looking@master ~]$ curl localhost:9200/bank/_alias?pretty{  "bank" : {    "aliases" : {      "bank_bak" : { }    }  }}

查询索引数据(全量数据)

[looking@master ~]$ curl -XGET localhost:9200/megacorp/employee/_search?pretty{  "took" : 3,  "timed_out" : false,  "_shards" : {    "total" : 1,    "successful" : 1,    "skipped" : 0,    "failed" : 0  },  "hits" : {    "total" : {      "value" : 2,      "relation" : "eq"    },    "max_score" : 1.0,    "hits" : [      {        "_index" : "megacorp",        "_type" : "employee",        "_id" : "1",        "_score" : 1.0,        "_source" : {          "first_name" : "Looking",          "last_name" : "Smith",          "age" : 25,          "about" : "I love to go rock climbing",          "interests" : [            "sports",            "music"          ]        }      },      {        "_index" : "megacorp",        "_type" : "employee",        "_id" : "3",        "_score" : 1.0,        "_source" : {          "first_name" : "Douglas",          "last_name" : "Fir",          "age" : 35,          "about" : "I like to build cabinets",          "interests" : [            "forestry"          ]        }      }    ]  }}

删除指定索引

[looking@master ~]$ curl -XDELETE localhost:9200/megacorp?pretty{  "acknowledged" : true}

查询集群文档数目

[looking@master ~]$ curl -X GET "localhost:9200/_count?pretty"{  "count" : 1005,  "_shards" : {    "total" : 6,    "successful" : 6,    "skipped" : 0,    "failed" : 0  }}

批量插入数据(从文件)

[looking@master ~]$ curl -XPOST 'localhost:9200/bank/account/_bulk?pretty' -H 'Content-Type: application/json' --data-binary "@accounts.json" ...    {      "index" : {        "_index" : "bank",        "_type" : "account",        "_id" : "990",        "_version" : 1,        "result" : "created",        "_shards" : {          "total" : 2,          "successful" : 1,          "failed" : 0        },        "_seq_no" : 998,        "_primary_term" : 1,        "status" : 201      }    },    {      "index" : {        "_index" : "bank",        "_type" : "account",        "_id" : "995",        "_version" : 1,        "result" : "created",        "_shards" : {          "total" : 2,          "successful" : 1,          "failed" : 0        },        "_seq_no" : 999,        "_primary_term" : 1,        "status" : 201      }    }  ]}

索引文档(插入数据)

[looking@master packages]$ curl -X PUT "localhost:9200/megacorp/employee/1?pretty" -H 'Content-Type: application/json' -d'> {>     "first_name" : "John",>     "last_name" :  "Smith",>     "age" :        25,>     "about" :      "I love to go rock climbing",>     "interests": [ "sports", "music" ]> }> '{  "_index" : "megacorp",  "_type" : "employee",  "_id" : "1",  "_version" : 1,  "result" : "created",  "_shards" : {    "total" : 2,    "successful" : 1,    "failed" : 0  },  "_seq_no" : 0,  "_primary_term" : 1}[looking@master packages]$ curl -X PUT "localhost:9200/megacorp/employee/2?pretty" -H 'Content-Type: application/json' -d'> {>     "first_name" :  "Jane",>     "last_name" :   "Smith",>     "age" :         32,>     "about" :       "I like to collect rock albums",>     "interests":  [ "music" ]> }> '[ "forestry" ]}'{  "_index" : "megacorp",  "_type" : "employee",  "_id" : "2",  "_version" : 1,  "result" : "created",  "_shards" : {    "total" : 2,    "successful" : 1,    "failed" : 0  },  "_seq_no" : 1,  "_primary_term" : 1}[looking@master packages]$ curl -X PUT "localhost:9200/megacorp/employee/3?pretty" -H 'Content-Type: application/json' -d'> {>     "first_name" :  "Douglas",>     "last_name" :   "Fir",>     "age" :         35,>     "about":        "I like to build cabinets",>     "interests":  [ "forestry" ]> }> '{  "_index" : "megacorp",  "_type" : "employee",  "_id" : "3",  "_version" : 1,  "result" : "created",  "_shards" : {    "total" : 2,    "successful" : 1,    "failed" : 0  },  "_seq_no" : 2,  "_primary_term" : 1}

检索文档(查询数据)

[looking@master packages]$ curl -X GET "localhost:9200/megacorp/employee/1?pretty"{  "_index" : "megacorp",  "_type" : "employee",  "_id" : "1",  "_version" : 1,  "_seq_no" : 0,  "_primary_term" : 1,  "found" : true,  "_source" : {    "first_name" : "John",    "last_name" : "Smith",    "age" : 25,    "about" : "I love to go rock climbing",    "interests" : [      "sports",      "music"    ]  }}

删除文档(删除数据)

[looking@master ~]$ curl -XDELETE localhost:9200/megacorp/employee/2?pretty{  "_index" : "megacorp",  "_type" : "employee",  "_id" : "2",  "_version" : 3,  "result" : "deleted",  "_shards" : {    "total" : 2,    "successful" : 1,    "failed" : 0  },  "_seq_no" : 7,  "_primary_term" : 11}------------------------------------------------------------[looking@master ~]$ curl -XGET localhost:9200/megacorp/employee/_search?pretty{  "took" : 1241,  "timed_out" : false,  "_shards" : {    "total" : 1,    "successful" : 1,    "skipped" : 0,    "failed" : 0  },  "hits" : {    "total" : {      "value" : 2,      "relation" : "eq"    },    "max_score" : 1.0,    "hits" : [      {        "_index" : "megacorp",        "_type" : "employee",        "_id" : "1",        "_score" : 1.0,        "_source" : {          "first_name" : "John",          "last_name" : "Smith",          "age" : 25,          "about" : "I love to go rock climbing",          "interests" : [            "sports",            "music"          ]        }      },      {        "_index" : "megacorp",        "_type" : "employee",        "_id" : "3",        "_score" : 1.0,        "_source" : {          "first_name" : "Douglas",          "last_name" : "Fir",          "age" : 35,          "about" : "I like to build cabinets",          "interests" : [            "forestry"          ]        }      }    ]  }}

更新文档(更新数据)

[looking@master ~]$ curl -XPOST 'localhost:9200/megacorp/employee/1/_update?pretty'  -H 'Content-Type: application/json' -d '{"doc":{  "first_name": "Looking"  }}'{  "_index" : "megacorp",  "_type" : "employee",  "_id" : "1",  "_version" : 4,  "result" : "updated",  "_shards" : {    "total" : 2,    "successful" : 1,    "failed" : 0  },  "_seq_no" : 8,  "_primary_term" : 11}------------------------------------------------------------[looking@master ~]$ curl -XGET localhost:9200/megacorp/employee/_search?pretty                                  {  "took" : 18,  "timed_out" : false,  "_shards" : {    "total" : 1,    "successful" : 1,    "skipped" : 0,    "failed" : 0  },  "hits" : {    "total" : {      "value" : 2,      "relation" : "eq"    },    "max_score" : 1.0,    "hits" : [      {        "_index" : "megacorp",        "_type" : "employee",        "_id" : "1",        "_score" : 1.0,        "_source" : {          "first_name" : "Looking",          "last_name" : "Smith",          "age" : 25,          "about" : "I love to go rock climbing",          "interests" : [            "sports",            "music"          ]        }      },      {        "_index" : "megacorp",        "_type" : "employee",        "_id" : "3",        "_score" : 1.0,        "_source" : {          "first_name" : "Douglas",          "last_name" : "Fir",          "age" : 35,          "about" : "I like to build cabinets",          "interests" : [            "forestry"          ]        }      }    ]  }}

条件搜索

[looking@master packages]$ curl -X GET "localhost:9200/megacorp/employee/_search?q=last_name:Smith&pretty"{  "took" : 178,  "timed_out" : false,  "_shards" : {    "total" : 1,    "successful" : 1,    "skipped" : 0,    "failed" : 0  },  "hits" : {    "total" : {      "value" : 2,      "relation" : "eq"    },    "max_score" : 0.47000363,    "hits" : [      {        "_index" : "megacorp",        "_type" : "employee",        "_id" : "1",        "_score" : 0.47000363,        "_source" : {          "first_name" : "John",          "last_name" : "Smith",          "age" : 25,          "about" : "I love to go rock climbing",          "interests" : [            "sports",            "music"          ]        }      },      {        "_index" : "megacorp",        "_type" : "employee",        "_id" : "2",        "_score" : 0.47000363,        "_source" : {          "first_name" : "Jane",          "last_name" : "Smith",          "age" : 32,          "about" : "I like to collect rock albums",          "interests" : [            "music"          ]        }      }    ]  }}

转载地址:http://hcjqi.baihongyu.com/

你可能感兴趣的文章
Python 图像处理库
查看>>
使用PHPMailer-master发送邮件
查看>>
利用smtp协议实现命令行发送邮件
查看>>
利用php的mail()函数发送邮件
查看>>
(一).postman学习——前期知识准备
查看>>
qt入门级使用
查看>>
Web Stotage——本地储存详解及案例
查看>>
File Reader文件操作
查看>>
地理位置服务——navigator.geolocation
查看>>
地理位置服务——百度地图API
查看>>
js拖放事件详解及实战
查看>>
js字符串常用属性与方法
查看>>
C++递归算法案例
查看>>
C++算法——异或运算解决出现次数问题
查看>>
C++数据结构——顺序栈(基本代码实现与案例)
查看>>
C++数据结构——链队列(基本代码实现与案例)
查看>>
C++数据结构——顺序表的查找(简单顺序查找、有序表的二分查找、索引顺序的查找)
查看>>
Hive 常用统计查询语句
查看>>
对象存储产生背景、发展历史、原理架构、优缺点、应用场景及开源项目对比
查看>>
Apache Ozone 分布式对象存储系统相关文档汇总
查看>>