ES 中的那些坑


數組

1. 數組中的 full-text 字段將被 【analyzed】

2. 數組中【所有元素】的數據類型必須一致

3. 數組的數據類型,以其 【第一個元素為准

 

映射

1. 數據類型會自動進行轉化,比如 123 可以被轉為 string ,但是 “test string” 沒法轉換為 long 類型

2. 使用 logstash 自動導入數據,filed 類型不一致將導致導入失敗

3. 動態模板設置中,要把更精細的控制寫在后面,否則精細的控制可能不會生效

正確示例
{
    "order": 0,
    "template": "woc_test",
    "settings": {
        "index.number_of_shards": "3"
    },
    "mappings": {
        "old_report_date": {
            "dynamic_templates": [
                {
                    "not_analyzed": {
                        "mapping": {
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "match_mapping_type": "string"     //該模板匹配范圍最廣,必須第一個寫,如果放在了最后,那么后面幾個精確控制的模板都不會生效
                    }
                },
                {
                    "遠程應用服務": {
                        "mapping": {
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "match": "遠程應用服務"
                    }
                },
                {
                    "啟用線路繁忙保護": {
                        "mapping": {
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "match": "啟用線路繁忙保護"
                    }
                },
                {
                    "排除IP地址": {
                        "mapping": {
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "match": "排除IP地址"
                    }
                },
                {
                    "其它": {
                        "mapping": {
                            "index": "analyzed",
                            "type": "string"
                        },
                        "path_match": "其它.*"
                    }
                }
            ]
        }
    },
    "aliases": {}
}

 

索引

1. 【同一個 _type】中 【相同 filed】 類型前后不一致將導致針對該 field 的搜索,搜索不到完整內容,甚至搜索不到任何內容

2. 【同一個 _index】中【不同 _type】 存在相同字段名,類型卻不同。那么針對整個 index 對該字段的 search 操作可能導致結果不正確。

 

時間類型

1. 自動識別的 date 類型,在存儲時候被轉為了【Numeric】類型,在搜索時候卻不會反轉,依然以 【Unix 時間戳】的形式返回

 

空字段

1. 空字段在 ES 中是不被保存的

  • "empty_string": ""
  • "null_value": null
  • "empty_array": []
  • "array_with_null_value": [ null ]

 

排序

多值字段

多值字段的值本身沒有固定的排序。

對於日期和數字類型(如 day_last:[100, 98, 80])可以使用 min、max、avg 或 sum 等方式來排序

"sort": {
    "dates": {
        "order": "asc",
        "mode": "min"
    }
}

 2. 字符串字段被 analyzed 后相當於是多值字段排序,對於類型為 string 的多值字段,排序一般不准確。

單值字段

1. 字符串字段被 not_analyzed 后相當於是單個字符串字段,對於類型為 string 的單值字段,排序會按默認字符順序來進行。(A<B<C)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM