<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ElasticSearch6.X查詢及相關基本操作 [TOC] ## 基礎概念 * 索引:含有相同屬性的文檔集合 相當于與SQL中database * 類型:索引可以定義一個或多個類型,文檔必須屬于一個類型 相當于與SQL中table * 文檔:文檔是可以被索引的基本數據單位 相當于與SQL中row * 分片:每個索引都有多個分片,每個分片是一個Lucene索引 * 備份:拷貝一份分片就完成了分片的備份 ### RESTFul API * api基本格式 `http://[ip]:[port]/[索引]/[類型]/[文檔id]` * 常用HTTP動詞 GET/PUT/DELETE/POST ### curl命令操作 * -X 指定http的請求方法 有 HEAD GET POST PUT DELETE * -d 指定要傳輸的數據 * -H 指定http請求頭信息 ## 使用curl命令操作elasticsearch ### **第一:`_cat`系列** cat系列提供了一系列查詢ES集群狀態的接口。 可以通過執行 `curl -XGET localhost:9200/_cat` 命令,獲取所有cat系列的操作: ~~~ [root@C20-23U-10 ~]# curl -XGET localhost:9200/_cat =^.^= /_cat/allocation 查看節點分配情況。 /_cat/shards 看分片情況。 /_cat/master 查看主節點。 /_cat/nodes 查看所有節點。 /_cat/indices 查看所用索引狀態。 /_cat/segments 查看索引的分片信息。 /_cat/count 查看文檔個數。 /_cat/health 查看集群健康情況。 ......... ~~~ 可以在下列命令后加上?v格式化輸出,也可以加上?help查看命令相關信息。結果如下: ```sh [root@zq-zabbix ~]# curl -XGET 172.17.19.29:9200/_cat/master BOO9Ur0dRoKZB_9dZIPtSg 172.17.19.29 172.17.19.29 node1-29 [root@zq-zabbix ~]# curl -XGET 172.17.19.29:9200/_cat/master?v id host ip node BOO9Ur0dRoKZB_9dZIPtSg 172.17.19.29 172.17.19.29 node1-29 ``` ## 查看集群是否健康 ` curl -XGET localhost:9200/_cat/health?v` 綠色——最健康的狀態,代表所有的主分片shard和副本分片replica都可用。 黃色——所有的主分片shard可用,但是部分副本分片replica不可用。 紅色——部分主分片shard不可用,此種情況需立即解決。 ### **第二:`_cluster`系列** 1、查詢集群健康狀態 ```sh [root@zq-zabbix ~]# curl -XGET 172.17.19.29:9200/_cluster/health?pretty=true { "cluster_name" : "zhangqi-es", "status" : "yellow", "timed_out" : false, "number_of_nodes" : 1, "number_of_data_nodes" : 1, "active_primary_shards" : 2012, "active_shards" : 2012, "relocating_shards" : 0, "initializing_shards" : 0, "unassigned_shards" : 1994, "delayed_unassigned_shards" : 0, "number_of_pending_tasks" : 0, "number_of_in_flight_fetch" : 0, "task_max_waiting_in_queue_millis" : 0, "active_shards_percent_as_number" : 50.22466300549176 #pretty=true表示格式化輸出 } ``` 2、顯示集群系統信息,包括CPU JVM等等 ```sh curl -XGET 172.17.19.29:9200/_cluster/stats?pretty=true ``` 3、集群的詳細信息。包括節點、分片等。 ```sh curl -XGET 172.17.19.29:9200/_cluster/state?pretty=true ``` 4、關閉節點 ```sh #關閉指定192.168.1.1節點 curl -XPOST ‘http://192.168.1.1:9200/_cluster/nodes/_local/_shutdown’ curl -XPOST ‘http://localhost:9200/_cluster/nodes/192.168.1.1/_shutdown’ #關閉主節點 curl -XPOST ‘http://localhost:9200/_cluster/nodes/_master/_shutdown’ #關閉整個集群 curl -XPOST ‘http://localhost:9200/_shutdown?delay=10s’ curl -XPOST ‘http://localhost:9200/_cluster/nodes/_shutdown’ curl -XPOST ‘http://localhost:9200/_cluster/nodes/_all/_shutdown’ ##delay=10s表示延遲10秒關閉 ``` ### **第三:`_nodes`系列** 1、查詢節點的狀態 ```sh curl -XGET ‘http://localhost:9200/_nodes/stats?pretty=true’ curl -XGET ‘http://localhost:9200/_nodes/192.168.1.2/stats?pretty=true’ curl -XGET ‘http://localhost:9200/_nodes/process’ curl -XGET ‘http://localhost:9200/_nodes/_all/process’ curl -XGET ‘http://localhost:9200/_nodes/192.168.1.2,192.168.1.3/jvm,process’ curl -XGET ‘http://localhost:9200/_nodes/192.168.1.2,192.168.1.3/info/jvm,process’ curl -XGET ‘http://localhost:9200/_nodes/192.168.1.2,192.168.1.3/_all curl -XGET ‘http://localhost:9200/_nodes/hot_threads ``` ### **第四:索引操作** 1、獲取索引 ``` curl -XGET ‘http://localhost:9200/{index}/{type}/{id}’ ``` 2、索引數據 ``` curl -XPOST ‘http://localhost:9200/{index}/{type}/{id}’ -d'{“a”:”avalue”,”b”:”bvalue”}’ ``` 3、刪除索引 ``` curl -XDELETE 'http://localhost:9200/{index}/{type}/{id}' curl -XDELETE 127.0.0.1:9200/logstash-2017.08.29 #可以使用通配符刪除統一后綴的索引 ``` 4、設置mapping ~~~ curl -XPUT http://localhost:9200/{index}/{type}/_mapping -d '{ "{type}" : { "properties" : { "date" : { "type" : "long" }, "name" : { "type" : "string", "index" : "not_analyzed" }, "status" : { "type" : "integer" }, "type" : { "type" : "integer" } } } }' ~~~ 5、獲取mapping curl -XGET http://localhost:9200/{index}/{type}/\_mapping 6、搜索 ~~~ curl -XGET 'http://localhost:9200/{index}/{type}/_search' -d '{ "query" : { "term" : { "user" : "kimchy" } //查所有 "match_all": {} }, "sort" : [{ "age" : {"order" : "asc"}},{ "name" : "desc" } ], "from":0, "size":100 } curl -XGET 'http://localhost:9200/{index}/{type}/_search' -d '{ "filter": {"and":{"filters":[{"term":{"age":"123"}},{"term":{"name":"張三"}}]}, "sort" : [{ "age" : {"order" : "asc"}},{ "name" : "desc" } ], "from":0, "size":100 } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看