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

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Nested 原文鏈接 : [https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html#nested](https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html#nested) 譯文鏈接 : [Nested](/display/Elasticsearch/Nested) 貢獻者 : [彭秋源](/display/~pengqiuyuan),[ApacheCN](/display/~apachecn),[Apache中文網](/display/~apachechina) ## 嵌套數據類型 `nested?`類型是一種對象類型的特殊版本,它允許索引對象數組,獨立地索引每個對象。 ## 如何使對象數組變扁平 內部類對象數組并不以你預料的方式工作。Lucene沒有內部對象的概念,所以Elasticsearch將對象層次扁平化,轉化成字段名字和值構成的簡單列表。比如,以下的文檔: ``` curl -XPUT 'localhost:9200/my_index/my_type/1?pretty' -d' { "group" : "fans", "user" : [ // 1 { "first" : "John", "last" : "Smith" }, { "first" : "Alice", "last" : "White" } ] }' ``` `user?`字段作為對象動態添加 在內部被轉化成如下格式的文檔: ``` { "group" : "fans", "user.first" : [ "alice", "john" ], "user.last" : [ "smith", "white" ] } ``` `user.first?`和?`user.last?`扁平化為多值字段,`alice?`和?`white?`的關聯關系丟失了。導致這個文檔錯誤地匹配對?`alice?`和?`smith?`的查詢: ``` curl -XGET 'localhost:9200/my_index/_search?pretty' -d' { "query": { "bool": { "must": [ { "match": { "user.first": "Alice" }}, { "match": { "user.last": "Smith" }} ] } } }' ``` ## 使用`nested`字段對應`object`數組 如果你需要索引對象數組,并且保持數組中每個對象的獨立性,你應該使用`nested`對象類型而不是`object`類型。`nested`對象將數組中每個對象作為獨立隱藏文檔來索引,這意味著每個嵌套對象都可以獨立被搜索: ``` curl -XPUT 'localhost:9200/my_index?pretty' -d' { "mappings": { "my_type": { "properties": { "user": { "type": "nested" // 1 } } } } }' curl -XPUT 'localhost:9200/my_index/my_type/1?pretty' -d' { "group" : "fans", "user" : [ { "first" : "John", "last" : "Smith" }, { "first" : "Alice", "last" : "White" } ] }' curl -XGET 'localhost:9200/my_index/_search?pretty' -d' { "query": { "nested": { "path": "user", "query": { "bool": { "must": [ { "match": { "user.first": "Alice" }}, { "match": { "user.last": "Smith" }} // 2 ] } } } } }' curl -XGET 'localhost:9200/my_index/_search?pretty' -d' { "query": { "nested": { "path": "user", "query": { "bool": { "must": [ { "match": { "user.first": "Alice" }}, { "match": { "user.last": "White" }} // 3 ] } }, "inner_hits": { // 4 "highlight": { "fields": { "user.first": {} } } } } } }' ``` | 1 | `user` 字段映射為 `nested` 類型而不是 `objec t`類型 | | 2 | 該查詢沒有匹配,因為 `Alice` 和 `Smith` 不在同一個嵌套類中 | | 3 | 該查詢有匹配,因為 `Alice` 和 `White` 在同一個嵌套類中 | | 4 | `inner_hits` 可以高亮匹配的嵌套文檔 | 嵌套文檔可以: | 1 | `使用 `[nested](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html "Nested Query")` `查詢來搜索 | | 2 | 使用 `[nested](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html "Nested Aggregation")` 和 [`reverse_nested`](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html "Reverse nested Aggregation")聚合來分析 | | 3 | 使用 [nested sorting](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html#nested-sorting "Sorting within nested objects.")來排序 | | 4 | 使用 [nested inner hits](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-inner-hits.html#nested-inner-hits "Nested inner hits") 來檢索和高亮 | ## `nested?`字段參數 | 參數 | 說明 | | dynamic | 新屬性是否應動態添加到現有對象。接受 true (默認), false 和 strict。 | | include_in_all | 為對象中的所有屬性設置默認的 `include_in_all` 值,對象本身沒有添加到 _all 字段。 | | properties | 對象內的字段,可以是任何數據類型,包括對象。可以將新屬性添加到現有對象。 | 注意 因為嵌套文檔是作為單獨的文檔被索引的,所以嵌套文檔只能被 `nested` 查詢、`nested / reverse_nested`或者 `nested inner hits` 訪問。 比如,一個 `string` 字段包含嵌套文檔,嵌套文檔中 `index_options` 設置為 `offsets` 以使用 postings highlighter,這些偏移量在主要的高亮階段是不可用的。必須通過 `nested inner hits` 來進行高亮操作。 ## 限制`nested`字段的數量 索引一個包含 100 個?`nested?`字段的文檔實際上就是索引 101 個文檔,每個嵌套文檔都作為一個獨立文檔來索引。為了防止過度定義嵌套字段的數量,每個索引可以定義的嵌套字段被限制在 50 個。
                  <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>

                              哎呀哎呀视频在线观看