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

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # Get API 原文鏈接 :[https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html) 譯文鏈接 :[Get API](/display/Elasticsearch/Get+API) 貢獻者 : [風輕云淡](/display/~wujian) **get api** 允許從一個基于其id的?**index** 中獲取一個 JSON格式的 **document**,下面的示例是從一個在名稱為tweet的?**type?**下的id為1,名稱為twitter的?**index?**中獲取一個JSON格式的?**document**。 ``` curl -XGET 'http://localhost:9200/twitter/tweet/1' ``` 以上 get 操作的結果如下 ``` { "_index" : "twitter", "_type" : "tweet", "_id" : "1", "_version" : 1, "found": true, "_source" : { "user" : "kimchy", "postDate" : "2009-11-15T14:12:12", "message" : "trying out Elasticsearch" } } ``` 以上結果包括?**document?**的?_index,_type,_id以及_version等我們想要檢索的,包括實際的?_source 如果它可以被發現(相應結果中的found字段) API還可以檢查 **document** 是否使用 HEAD,例如: ``` curl -XHEAD -i 'http://localhost:9200/twitter/tweet/1' ``` ## Realtime 默認情況下,get API 是實時的,而且它不受 **index** 刷新頻率的影響(當數據對search操作可見)。如果 **document** 已經修改完但沒還有刷新,get API將會執行 in-place刷新操作使得 **document** 可見。這也會導致其他 **docuemnt** 發生改變。若要禁止 GET的實時操作,可以設置?**realtime** 參數為false。 ## Option Type get API允許?`_type 作為可選參數,設置它為_all可以從所有的匹配的**type**中獲取第一個 **docuemnt**。` ## Source filtering 默認情況下,get 操作返回?_source字段的內容,除非你使用stored_fields參數或_source字段是禁止的。你可以使用_source參數來關閉_source檢索。 ``` curl -XGET 'http://localhost:9200/twitter/tweet/1?_source=false' ``` 如果你只需要從完整的_source中獲取一個或兩個字段,你可以使用_source_include?&`_source_exclude`?參數用來包含或過濾其他部分。這個功能很有用在大文件?**document** 部分檢索的時候可以節省網絡開銷。所有的參數可以用普通的分隔符連接或者通配符表達式。示例如下: ``` curl -XGET 'http://localhost:9200/twitter/tweet/1?_source_include=*.id&_source_exclude=entities' ``` 如果你只是想要指定包含的,你可以使用比較剪短的表達式: ``` curl -XGET 'http://localhost:9200/twitter/tweet/1?_source=*.id,retweeted' ``` ## Stored Fields get 操作允許指定一系列的stored 字段,這些字段將會被返回通過傳遞stored_fields參數。如果請求的字段沒有被儲存,將會被忽略。參考以下示例: ``` PUT twitter { "mappings": { "tweet": { "properties": { "counter": { "type": "integer", "store": false }, "tags": { "type": "keyword", "store": true } } } } } ``` 現在我們可以添加 document: ``` PUT twitter/tweet/1 { "counter" : 1, "tags" : ["red"] } ``` 1.嘗試去檢索: ``` GET twitter/tweet/1?stored_fields=tags,counter ``` 以上get操作的結果是: ``` { "_index": "twitter", "_type": "tweet", "_id": "1", "_version": 1, "found": true, "fields": { "tags": [ "red" ] } } ``` 從?**document** 中獲取的字段的值通常是array。由于counter字段沒有存儲,當嘗試獲取stored_fields時get會將其忽略。 可以對元數據字段進行檢索,比如_routing和_parent: ``` PUT twitter/tweet/2?routing=user1 { "counter" : 1, "tags" : ["white"] } GET twitter/tweet/2?routing=user1&stored_fields=tags,counter ``` 以上get操作的結果是: ``` { "_index": "twitter", "_type": "tweet", "_id": "2", "_version": 1, "_routing": "user1", "found": true, "fields": { "tags": [ "white" ] } } ``` 只有leaf的字段可以通過stored_field選項返回。所以object字段無法返回并且這個請求會失敗 ## Generated fields 如果在索引和刷新過程中沒有發生刷新操作,GET會訪問transaction日志來獲取?**document**。然而,一些字段只會在索引時創建。如果你嘗試訪問那些只有在創建索引時才會創建的字段,默認情況下會得到一個異常。你可以通過設置?**ignore_errors_on_generated_fields=true?**來忽略那些字段。 ## Getting the _source directly 使用/{index}/{type}/{id}/_source 可以只獲取?**document?**的_source字段,不會有其他多余的內容,例如:? ``` curl -XGET 'http://localhost:9200/twitter/tweet/1/_source' ``` 你也可以使用過濾參數來控制_source的哪些部分可以被返回: ``` curl -XGET 'http://localhost:9200/twitter/tweet/1/_source?_source_include=*.id&_source_exclude=entities' ``` 注意,同樣有一個HEAD變量來檢測document??_source 是否存在。一個存在的?**document** 不會有_source,如果它在?**mapping?**里被禁止,例如: ``` curl -XHEAD -i 'http://localhost:9200/twitter/tweet/1/_source' ``` ## Routing 當創建索引時想要控制路由,為了獲取?**document**,routing 的值也因該提供,例如: ``` curl -XGET 'http://localhost:9200/twitter/tweet/1?routing=kimchy' ``` 以上的操作會獲取id為1的tweet,但是是基于用戶被路由的。注意,如果沒有設置正確的路由,將會導致?**document?**無法被獲取。 ## Preference 控制共享的副本去執行get請求的優先權。默認情況下,是在共享的副本中隨機操作的。 `preference`?可以設置為: _primary ? ? 操作會在主要的共享副本執行。 _local ? ?操作會優先在本地的共享副本執行 Custom(String)value ? 自定義值會被用來保證相同的共享副本使用相同的自定義值。這個幫助?"jumping values" 當不同的共享副本在不同的refresh?states。這個值類似于web session id或者user name。? ## Refresh refresh 參數可以設置為true,為了使其能在get操作和使其可檢索前刷新相關的共享副本。將其設置為true應該要謹慎,應為這將導 致系統資源負載增大(也會減慢索引的創建)。 ## Distributed get操作會從一個指定的副本id得到散列值。然后會重定向到那個shard id的其中一個副本上并返回結果。副本是primary shard而且他的副本是在同一個shard id 組。這意味著副本數越多,GET的性能越好。 ## Versioning support 你可以使用 version 參數去檢索 **document**,只有在當前的 version 和你指定的version 相同的情況下。這個特性同樣適用于所有的 version types,當我們希望要檢索的?**document?**的version與我們指定的version相同。 在內部,**Elasticsearch** 已經標記了已經刪除的舊的?**document** 并且增加了新的?**document**。舊版本的?**document?**不會馬上出現,并且你也不能訪問。**Elasticsearch** 會在后臺清理已經刪除的**document?**以便可以索引更多的數據。
                  <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>

                              哎呀哎呀视频在线观看