Mowei
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    ElasticSearch 欄位資料型態 === [Field data types](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html) --- ## Dynamic mapping and Explicit mappings --- ## 動態 Mapping - Elasticsearch僅通過索引文檔即可自動添加新欄位。 :::info 使用[Dynamic templates](https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html)來定義自定義映射,這些自定義映射將基於匹配條件動態添加欄位。 ::: --- ## 明確 Mapping 在建立index的時候創建映射類型和欄位映射,或通過mapping API添加映射類型和欄位到一個已經存在的index中。 --- 建立Index ```json= PUT /my-index-000001 { "mappings": { "properties": { "age": { "type": "integer" }, "email": { "type": "keyword" }, "name": { "type": "text" } } } } ``` --- 新增欄位 ```json= PUT /my-index-000001/_mapping { "properties": { "employee-id": { "type": "keyword", "index": false } } } ``` --- # String datatypes --- 1. Text - 用於索引全文值的字段,分析過程允許Elasticsearch搜索每個全文字段中的單個單詞。文本字段不用於排序,很少用於聚合。 --- 2. Keyword - 用於索引結構化內容的字段,它們通常用於過濾、排序和聚合。關鍵字字段只能按其確切值進行搜索。 --- # Numeric datatypes - Long: 帶符號64位元整數 (-2^64^ ~ 2^64^-1) - Integer: 帶符號32位元整數 (-2^32^ ~ 2^32^-1) - Short:帶符號16位元整數 (-2^16^ ~ 2^16^-1) - Byte:帶符號8位元整數 (-2^8^ ~ 2^8^-1) - Double: 雙精度64位元浮點數 - Float:精度32位元浮點數 - Half_float:半精度16位元浮點數 - Scaled_float:會透過 scaling factor把浮點數字變成整數 --- ```json= PUT my-index-000001 { "mappings": { "properties": { "number_of_bytes": { "type": "integer" }, "time_in_seconds": { "type": "float" }, "price": { "type": "scaled_float", "scaling_factor": 100 } } } } ``` --- # Date datatype JSON沒有日期數據類型,因此Elasticsearch中的日期可以是: - 包含格式化日期的字符串 "2015-01-01"或"2015/01/01 12:10:30"。 - 一個自紀元以來毫秒數的數字。 - 一個自紀元以來秒數的數字。 --- 日期格式可以自定義,但是如果未指定,則預設使用: :::info "strict_date_optional_time||epoch_millis" ::: ```json= PUT my-index-000001/_doc/1 { "date": "2015-01-01" } PUT my-index-000001/_doc/2 { "date": "2015-01-01T12:10:30Z" } PUT my-index-000001/_doc/3 { "date": 1420070400001 } ``` --- # Boolean datatype 布林字段接受JSON true和false值,但也可以接受被解釋為true或false的字符串。 - False values: false , "false" - True valus: true, "true" --- # Binary datatype 二進制類型接受二進制值作為Base64編碼的字符串。 默認情況下不存儲該字段,並且不可搜索。 --- ```json= PUT my-index { "mappings" : { "properties" : { "rawdata" : { "type" : "binary" } } } } ``` ```json= POST my-index2/_doc/ { "rawdata" : "aGVsbG93b3JsZA==" } ``` --- # Range datatype <!-- .slide: style="font-size: 32px;" --> Range型態支持 - Integer_range:一個帶符號32位元Range (-2^32^ ~ 2^32^-1) - Float_range: 一個精度32位元浮點數Range - Long_range: 一個帶符號64位元Range(-2^64^ ~ 2^64^-1) - Dobule_range: 一個雙精度64位元浮點數Range - Date_range:自系統紀元以來經過的無符號64位整數毫秒。 - Ip_range: 支持IPv4或IPv6(或混合)地址的一系列ip值 --- ```json= PUT range_index { "settings": { "number_of_shards": 2 }, "mappings": { "properties": { "expected_attendees": { "type": "integer_range" }, "time_frame": { "type": "date_range", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" } } } } ``` --- ```json= PUT range_index/_doc/1?refresh { "expected_attendees" : { "gte" : 10, "lt" : 20 }, "time_frame" : { "gte" : "2015-10-31 12:00:00", "lte" : "2015-11-01" } } ``` --- ```json= GET range_index/_search { "query" : { "range" : { "time_frame" : { "gte" : "2015-10-31", "lte" : "2015-11-01", "relation" : "within" } } } } ``` --- # Array datatype 在Elasticsearch中,沒有專用的Array類型。預設情況下,任何字段都可以包含零個或多個值,而 Array 中的所有值必須具有相同的資料類型。 例如: - 字串陣列: ["one","two"] - 數值陣列: [1,2] - 陣列的陣列: [1, [2,3]] 相當於 [1,2,3] - 物件陣列: [{"name":"Mary","age":12}, {"name":"John","age":10}] --- # Object datatype - JSON文檔本質上是分層的:文檔可能包含內部物件,而內部物件本身可能包含內部物件: ```json= PUT my-index-000001/_doc/1 { "region": "US", "manager": { "age": 30, "name": { "first": "John", "last": "Smith" } } } ``` --- # Nested datatype nested類型是特殊的object型別,它允許物件陣列以可以彼此獨立查詢的方式進行索引。 [說明](https://www.elastic.co/guide/en/elasticsearch/reference/master/nested.html) --- ## object arrary 如何展平 Lucene沒有內部物件的概念,因此Elasticsearch將物件層次結構展平為一個簡單的字段名稱和值列表。 例如,以下文件: --- ```json= PUT my-index-000001/_doc/1 { "group" : "fans", "user" : [ { "first" : "John", "last" : "Smith" }, { "first" : "Alice", "last" : "White" } ] } ``` --- ```json= GET my-index-000001/_search { "query": { "bool": { "must": [ { "match": { "user.first": "Alice" } }, { "match": { "user.last": "Smith" } } ] } } } ``` --- 內部轉換成像這樣的文檔 其中 alice 和 white 的關聯性丟失了 ```json= { "group" : "fans", "user.first" : [ "alice", "john" ], "user.last" : [ "smith", "white" ] } ``` --- 使用nested類型 ```json= PUT my-index-000002 { "mappings": { "properties": { "user": { "type": "nested" } } } } ``` --- 搜尋 nested field type 需使用 nested query ```json= GET my-index-000002/_search { "query": { "nested": { "path": "user", "query": { "bool": { "must": [ { "match": { "user.first": "Alice" } }, { "match": { "user.last": "Smith" } } ] } } } } } ``` :::info 如果需要索引object arrary 並保持數組中每個對象的獨立性,請使用nested數據類型而不是 object數據類型。 ::: --- # 敬請指教 ----

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully