<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>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                [TOC] ## 新增記錄 ### 以 PUT 方式,需要在url 中添加id ``` $ curl -X PUT 'localhost:9200/accounts/person/1' -d ' { "user": "張三", "title": "工程師", "desc": "數據庫管理" }' ``` 返回 ``` { "_index":"accounts", "_type":"person", "_id":"1", "_version":1, "result":"created", "_shards":{"total":2,"successful":1,"failed":0}, "created":true } ``` ### 以post 方式 ,不需要加 id 自動生成的id 是個隨機數 ``` $ curl -X POST 'localhost:9200/accounts/person' -d ' { "user": "李四", "title": "工程師", "desc": "系統管理" }' ``` 返回 ``` { "_index":"accounts", "_type":"person", "_id":"AV3qGfrC6jMbsbXb6k1p", "_version":1, "result":"created", "_shards":{"total":2,"successful":1,"failed":0}, "created":true } ``` > 生成數據時如果沒有先創建 index 即`accounts`也不會報錯,而是直接手動生成對應的index ## 查看記錄 `curl 'localhost:9200/accounts/person/1?pretty=true'` - pretty=true 返回易讀的格式 - accounts/person/1 id 為1 success ``` { "_index" : "accounts", "_type" : "person", "_id" : "1", "_version" : 1, "found" : true, "_source" : { "user" : "張三", "title" : "工程師", "desc" : "數據庫管理" } } ``` error ``` { "_index" : "accounts", "_type" : "person", "_id" : "abc", "found" : false } ``` ## 刪除記錄 ` curl -X DELETE 'localhost:9200/accounts/person/1'` ## 更新記錄 ``` $ curl -X PUT 'localhost:9200/accounts/person/1' -d ' { "user" : "張三", "title" : "工程師", "desc" : "數據庫管理,軟件開發" }' ``` 返回值 ``` { "_index":"accounts", "_type":"person", "_id":"1", "_version":2, //版本信息發送變化 "result":"updated", "_shards":{"total":2,"successful":1,"failed":0}, "created":false } ``` ## 查詢 ### 返回所有記錄 `curl 'localhost:9200/accounts/person/_search'` ``` { "took":2, "timed_out":false, "_shards":{"total":5,"successful":5,"failed":0}, "hits":{ "total":2, "max_score":1.0, "hits":[ ... took 返回記錄數,本例是2條。 max_score:最高的匹配程度,本例是1.0。 hits:返回的記錄組成的數組 ``` ### 全文搜索 GET 請求帶有數據體 ``` $ curl 'localhost:9200/accounts/person/_search' -d ' { "query" : { "match" : { "desc" : "軟件" }}, "from": 1, "size": 1 //Elastic 默認一次返回10條結果 }' ``` ### 邏輯運算 ``` $ curl 'localhost:9200/accounts/person/_search' -d ' { "query" : { "match" : { "desc" : "軟件 系統" }} }' ``` 使用 or 查詢 如果要使用 and 可使用下面的方式 ``` curl 'localhost:9200/accounts/person/_search' -d ' { "query": { "bool": { "must": [ { "match": { "desc": "軟件" } }, { "match": { "desc": "系統" } } ] } } }' ``` ## 聚合查找 Elasticsearch 的聚合操作有兩個主要的概念: * 桶(Buckets):滿足特定條件的文檔的集合 * 指標(Metrics):對桶內的文檔進行統計計算 桶的概念上類似于 SQL 的分組(`group by`),而指標類似于`count()`、`sum()`、`max()`等統計方法 ### 字符串開啟聚合 默認情況下,文本字段禁用Fielddata。 在[name]上設置fielddata=true,以便通過取消反轉索引來在內存中加載fielddata。 但是請注意,這可能會占用大量內存。 或者使用關鍵字字段 ### Terms 將一個或多個字段分組 ``` { "size" : 0, "aggs": { "terms_classNo": { "terms": { "field": "classNo" } } } } ``` > **terms_classNo** 是自定義變量名,將會在返回值中展示,**classNo** 為字段名 ### Range ``` { "size" : 0, "aggs": { "range_age": { "range": { "field": "age", "ranges": [ { "to": 10 }, { "from": "11", "to": "15" }, { "from": "16" } ] } } } } ``` ## Metrics(指標) 如 sum , max 等 ``` { "size" : 0, "aggs" : { "avg_grade" : { "terms": { "field": "classNo" }, "aggs": { "avg_grade": { "avg": {"field": "price"} } } } } } ```
                  <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>

                              哎呀哎呀视频在线观看