<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之旅 廣告
                [TOC] # 類型映射關系 ## 核心數據類型 * 字符串 - text * 用于全文索引,該類型的字段將通過分詞器進行分詞,最終用于構建索引 * 字符串 - keyword * 不分詞,只能搜索該字段的完整的值,只用于 filtering * 數值型 * long:有符號64-bit integer:-2^63 ~ 2^63 - 1 * integer:有符號32-bit integer,-2^31 ~ 2^31 - 1 * short:有符號16-bit integer,-32768 ~ 32767 * byte: 有符號8-bit integer,-128 ~ 127 * double:64-bit IEEE 754 浮點數 * float:32-bit IEEE 754 浮點數 * half\_float:16-bit IEEE 754 浮點數 * scaled\_float * 布爾 - boolean * 值:false, "false", true, "true" * 日期 - date * 由于Json沒有date類型,所以es通過識別字符串是否符合format定義的格式來判斷是否為date類型 * format默認為:`strict_date_optional_time||epoch_millis` [format](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html) * 二進制 - binary * 該類型的字段把值當做經過 base64 編碼的字符串,默認不存儲,且不可搜索 * 范圍類型 * 范圍類型表示值是一個范圍,而不是一個具體的值 * 譬如 age 的類型是 integer\_range,那么值可以是 {"gte" : 10, "lte" : 20};搜索 "term" : {"age": 15} 可以搜索該值;搜索 "range": {"age": {"gte":11, "lte": 15}} 也可以搜索到 * range參數 relation 設置匹配模式 * INTERSECTS :默認的匹配模式,只要搜索值與字段值有交集即可匹配到 * WITHIN:字段值需要完全包含在搜索值之內,也就是字段值是搜索值的子集才能匹配 * CONTAINS:與WITHIN相反,只搜索字段值包含搜索值的文檔 * integer\_range * float\_range * long\_range * double\_range * date\_range:64-bit 無符號整數,時間戳(單位:毫秒) * ip\_range:IPV4 或 IPV6 格式的字符串 ~~~ # 創建range索引 PUT range_index { "mappings": { "_doc": { "properties": { "expected_attendees": { "type": "integer_range" }, "time_frame": { "type": "date_range", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" } } } } } # 插入一個文檔 PUT range_index/_doc/1 { "expected_attendees" : { "gte" : 10, "lte" : 20 }, "time_frame" : { "gte" : "2015-10-31 12:00:00", "lte" : "2015-11-05" } } # 12在 10~20的范圍內,可以搜索到文檔1 GET range_index/_search { "query" : { "term" : { "expected_attendees" : { "value": 12 } } } } # within可以搜索到文檔 # 可以修改日期,然后分別對比CONTAINS,WITHIN,INTERSECTS的區別 GET range_index/_search { "query" : { "range" : { "time_frame" : { "gte" : "2015-11-02", "lte" : "2015-11-03", "relation" : "within" } } } } ~~~ ## 復雜數據類型 * 數組類型 Array * 字符串數組 \[ "one", "two" \] * 整數數組 \[ 1, 2 \] * 數組的數組 \[ 1, \[ 2, 3 \]\],相當于 \[ 1, 2, 3 \] * Object對象數組 \[ { "name": "Mary", "age": 12 }, { "name": "John", "age": 10 }\] * 同一個數組只能存同類型的數據,不能混存,譬如 \[ 10, "some string" \] 是錯誤的 * 數組中的 null 值將被 null\_value 屬性設置的值代替或者被忽略 * 空數組 \[\] 被當做 missing field 處理 * 對象類型 Object * 對象類型可能有內部對象 * 被索引的形式為:manager.name.first ~~~ # tags字符串數組,lists 對象數組 PUT my_index/_doc/1 { "message": "some arrays in this document...", "tags": [ "elasticsearch", "wow" ], "lists": [ { "name": "prog_list", "description": "programming list" }, { "name": "cool_list", "description": "cool stuff list" } ] } ~~~ ## 嵌套類型Nested nested 類型是一種對象類型的特殊版本,它允許索引對象數組,**獨立地索引每個對象** **嵌套類型與Object類型的區別** 通過例子來說明: 1. 插入一個文檔,不設置mapping,此時 user 字段被自動識別為**對象數組** ~~~ DELETE my_index PUT my_index/_doc/1 { "group" : "fans", "user" : [ { "first" : "John", "last" : "Smith" }, { "first" : "Alice", "last" : "White" } ] } ~~~ 2. 查詢 user.first為 Alice,user.last 為 Smith的文檔,理想中應該找不到匹配的文檔 3. 結果是查到了文檔1,為什么呢? ~~~ GET my_index/_search { "query": { "bool": { "must": [ { "match": { "user.first": "Alice" }}, { "match": { "user.last": "Smith" }} ] } } } ~~~ 4. 是由于Object對象類型在內部被轉化成如下格式的文檔: ~~~ { "group" : "fans", "user.first" : [ "alice", "john" ], "user.last" : [ "smith", "white" ] } ~~~ 5. user.first 和 user.last 扁平化為多值字段,alice 和 white 的**關聯關系丟失了**。導致這個文檔錯誤地匹配對 alice 和 smith 的查詢 6. 如果最開始就把user設置為 nested 嵌套對象呢? ~~~ DELETE my_index PUT my_index { "mappings": { "_doc": { "properties": { "user": { "type": "nested" } } } } } PUT my_index/_doc/1 { "group": "fans", "user": [ { "first": "John", "last": "Smith" }, { "first": "Alice", "last": "White" } ] } ~~~ 7. 再來進行查詢,可以發現以下第一個查不到文檔,第二個查詢到文檔1,符合我們預期 ~~~ GET my_index/_search { "query": { "nested": { "path": "user", "query": { "bool": { "must": [ { "match": { "user.first": "Alice" }}, { "match": { "user.last": "Smith" }} ] } } } } } GET my_index/_search { "query": { "nested": { "path": "user", "query": { "bool": { "must": [ { "match": { "user.first": "Alice" }}, { "match": { "user.last": "White" }} ] } }, "inner_hits": { "highlight": { "fields": { "user.first": {} } } } } } } ~~~ 8. nested對象將數組中每個對象作為獨立隱藏文檔來索引,這意味著每個嵌套對象都可以獨立被搜索 9. 需要注意的是: * 使用 [nested 查詢](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html)來搜索 * 使用 nested 和 [reverse\_nested](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html) 聚合來分析 * 使用 [nested sorting](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html#nested-sorting) 來排序 * 使用 [nested inner hits](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-inner-hits.html#nested-inner-hits) 來檢索和高亮 ## 地理位置數據類型 * geo\_point * 地理位置,其值可以有如下四中表現形式: * object對象:"location": {"lat": 41.12, "lon": -71.34} * 字符串:"location": "41.12,-71.34" * [geohash](http://geohash.gofreerange.com/):"location": "drm3btev3e86" * 數組:"location": \[ -71.34, 41.12 \] * 查詢的時候通過 [Geo Bounding Box Query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-bounding-box-query.html) 進行查詢 * geo\_shape ## 專用數據類型 * 記錄IP地址 ip * 實現自動補全 completion * 記錄分詞數 token\_count * 記錄字符串hash值 murmur3 * Percolator ~~~ # ip類型,存儲IP PUT my_index { "mappings": { "_doc": { "properties": { "ip_addr": { "type": "ip" } } } } } PUT my_index/_doc/1 { "ip_addr": "192.168.1.1" } GET my_index/_search { "query": { "term": { "ip_addr": "192.168.0.0/16" } } } ~~~ ## 多字段特性 multi-fields * 允許對同一個字段采用不同的配置,比如分詞,常見例子如對人名實現拼音搜索,只需要在人名中新增一個**子字段**為 pinyin 即可 * 通過參數 fields 設置
                  <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>

                              哎呀哎呀视频在线观看