<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智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                **這篇是前幾年的筆記, 有些在7.x用不了了** https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html **從6.x開始每個索引只能使用一個類型(type), 并且未來將去掉類型(type) 6.x 很多地方要加 _doc** 1. 索引 1.1 添加索引 PUT product 返回 { "acknowledged": true, "shards_acknowledged": true, "index": "product" } 1.2 創建 mapping 映射 ES中創建一個mapping映射類似于在數據庫中定義表結構,即表里面有哪些字段、字段是什么類型、字段的默認值等;也類似于solr里面的模式schema的定義 未創建索引的情況下 "type" : "text", 表示是文本類型, 會被分詞 "type" : "keyword", 和text 類似, 但不會被分詞, 值將作為一個整體 "index": false 表示不會被查詢 PUT product { "mappings" : { "properties" : { "name" : { "type" : "text", "index": true }, "desc": { "type" : "text" }, "price" : { "type" : "keyword", "index": true }, "producer": { "type" : "text" }, "ssss": { "type" : "text", "index": false } } } } 為已存在的索引創建或創建mappings 目前6.x 不使用_doc 會報錯 "reason": "Validation Failed: 1: mapping type is missing;" POST /product/_doc/_mapping { "properties": { "name": { "type": "text", "index": true } } } GET?????/hp_goods/_doc/_search // null_value 是加默認值 PUT??/hp_goods/_doc/_mapping { ??"properties":?{ ????"isDel":?{ ??????"type":?"integer", ??????"null_value":?0 ????} ??} } 1.3 mapping 增加數據 值一旦創建, 無法修改, 只能添加新值 如 tag 已經有了, 則無法修改其內容, 只能新增tags POST /product/_doc/_mapping { "properties": { "tags": { "type": "text" } } } 或者 POST /product { "mappings": { "properties": { "tags": { "type": "text" } } } } 1.4 遷移數據 properties 里的具體值 一旦新建則無法修改 如果必須修改則要重建索引 需要新建 index 索引, 把之前的index 數據遷移到新的索引 獲取當前 index 的結構 GET /product/_mapping 新建新的索引, 結構從上面復制進行修改 POST /newproduct { "mappings": { "properties": { "tags": { "type": "text" } } } } 遷移 1.5 刪除索引 DELETE product 2 文檔 2.1 添加文檔 PUT /product/_doc/1 { "name" : "gaolujie yagao", "desc" : "gaoxiao meibai", "price" : 30, "producer": "gaolujie producer", "tags": [ "meibai", "fangzhu" ] } 2.2 刪除文檔 DELETE /product/_doc/1 2.3 修改文檔 局部修改 POST 方式 id后面跟著 /_update, 里面使用 doc 包裹數據 POST /product/_doc/1/_update { "doc": { "price" : 50 } } // 7.4 版本, 現在是這樣修改 POST /product/_update/1 { "doc": { "price": 50 } } 全量修改 和添加時的代碼結構是一樣的, 如果數據和添加時的數據不一樣, 不同的部門會刪除掉 "price" : 30, 在這里就被刪除了 PUT /product/_doc/1 { "name" : "gaolujie yagao", "desc" : "gaoxiao meibai", "producer": "gaolujie producer", "tags": [ "meibai", "fangzhu" ] } 每次修改后,version會更改, 同一個文檔連續多次刪除, version也會累加 2.4 簡單查詢 2.4.1 查詢全部 GET /product/_doc/_search hits 查詢到的數據信息 _score 是數據的匹配度 _source 是返回的數據的哪些字段, 默認全部(類似數據庫的 * ) { "took": 3, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 2, "max_score": 1, "hits": [ { "_index": "product", "_type": "_doc", "_id": "2", "_score": 1, "_source": { "name": "gaolujie yagao", "desc": "gaoxiao meibai", "price": 30, "producer": "gaolujie producer", "tags": [ "meibai", "fangzhu" ] } }, { "_index": "product", "_type": "_doc", "_id": "1", "_score": 1, "_source": { "name": "gaolujie yagao", "desc": "gaoxiao meibai", "price": 50, "producer": "gaolujie producer", "tags": [ "meibai", "fangzhu" ] } } ] } } 2.4.2 判斷數據是否存在 不存在返回404狀態碼 HEAD /product/_doc/11 存在返回200狀態碼 HEAD /product/_doc/1 2.4.3 定制返回的字段(_source) 多個用 , 逗號隔開 返回的_source結果只會有name,desc GET /product/_doc/_search?_source=name,desc 3. 樂觀鎖并發控制 6.7 以前 使用version , 以后用 if_seq_no=2&if_primary_term=1 當給一個新增加的數據做更新操作時, 第一次更新可以完成, 因為version=1是當前版本號, 當第二次更新時, 由于版本號傳還是1, 但是實際最新的已經是2了, 會報版本沖突錯誤. 改為最新的才會成功. 用于解決并發問題, 倆個客戶端, 都傳version=1, 當一個修改成功后, version為2了, 另一個就會更新失敗 高版本es 把 version 換為 if_seq_no和if_primary_term POST /product/_doc/1/_update?version=1 { "doc": { "price" : 51 } } 對于if_primary_term記錄的就是具體的哪個主分片, 而if_seq_no這個參數起的作用和舊版本中的_version是一樣的 4. DSL 查詢 4.1 term查詢 term 不會把查詢條件進行分詞后查詢, 作為一整個關鍵詞去搜索 POST /shop/_doc/_search { "query":{ "term":{ "desc":"中國" } } } 4.2 查詢表達式分詞搜索 是條件分詞查詢, 先把查詢條件進行分詞后查詢 term 換成 match, 條件被分詞了, 查詢結果變了 POST /shop/_doc/_search { "query":{ "match":{ "desc":"中國" } } } 4.3 多個詞語匹配檢索 相當于是tag標簽查詢, 所有帶數組里其中一個詞語的數據, 就會被查詢到 POST /shop/_doc/_search { "query":{ "terms":{ "desc": ["中國", "學生"] } } } 4.4 短語搜索 match_phrase的分詞結果必須在text字段分詞中都包含,而且順序必須相同,而且必須且都是連續的 POST /shop/_doc/_search { "query" : { "match_phrase" : { "desc" : "導游坐飛機去海外旅游" } } } 4.5 查詢全部 match_all POST /shop/_doc/_search { "query": { "match_all": {} }, "_source": ["id", "nickname", "age"] } 4.6 使用過濾器的模糊查詢 gte >= gt > lte <= lt < POST /shop/_doc/_search { "query" : { "bool": { "must": { "match" : { "nickname" : "飛翔" } }, "filter": { "range" : { "age" : { "gt" : 19 } } } } } } 4.7 分頁查詢 from 起始查詢索引 size 每次返回數量 POST /shop/_doc/_search { "query": { "match_all": {} }, "_source": [ "id", "nickname", "age" ], "from": 2, "size": 10, "sort": ["age"] } 4.8 match(operator) "operator": or:搜索內容分詞后,只要存在一個詞語匹配就展示結果 and:搜索內容分詞后,都要滿足詞語匹配 POST /shop/_doc/_search { "query" : { "match" : { "desc" : { "query": "學習慕課網", "operator": "or" } } } } minimum_should_match: 最低匹配精度,至少有[分詞后的詞語個數]x百分百,得出一個數據值取整。舉個例子:當前屬性設置為70,若一個用戶查詢檢索內容分詞后有10個詞語,那么匹配度按照 10x70%=7,則desc中至少需要有7個詞語匹配,就展示;若分詞后有8個,則 8x70%=5.6,則desc中至少需要有5個詞語匹配,就展示。 minimum_should_match 也能設置具體的數字,表示個數 POST /shop/_doc/_search { "query": { "match": { "desc": { "query": "女友生日送我好玩的xbox游戲機", "minimum_should_match": "60%" } } } } 4.9 ids查詢 POST /shop/_doc/_search { "query": { "ids": { "type": "_doc", "values": ["1001", "1010", "1008"] } } } 4.10 multi_match 滿足使用match在多個字段中進行查詢的需求 POST /shop/_doc/_search { "query" : { "multi_match" : { "query": "慕課網", "fields": [ "desc", "nickname" ] } } } 4.11 boost 權重, 為某個字段設置權重,權重越高,文檔相關性得分就越高。通暢來說搜索商品名稱要比商品簡介的權重更高。 POST /shop/_doc/_search { "query": { "multi_match": { "query": "皮特帕克慕課網", "fields": ["desc", "nickname^10"] } } } nickname^10 代表搜索提升10倍相關性,也就是說用戶搜索的時候其實以這個nickname為主,desc為輔,nickname的匹配相關度當然要提高權重比例了。
                  <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>

                              哎呀哎呀视频在线观看