2011-12-13 64 views
1

我是一般的新增elasticsearch和nosql文檔模型。NULL字段文檔模型

在elasticsearch中對於空字段的最佳做法是什麼?

我們應該將它聲明爲null還是完全保留它?

例如:電子郵件字段

[{ 
    id:1, 
    name:"John", 
    email:"[email protected]" 
}, 
{ 
    id:2, 
    name:"David", 
    email:null 
}, 
{ 
    id:3, 
    name:"Tony" 
}] 

回答

2

要與空場做的是完全取決於你。默認情況下,ES將完全忽略空字段。如果需要,也可以在空字段的文檔映射中指定默認值。

映射例如:

{ 
    "_default_" : { 
     "properties" : { 
      "id" : {"type" : "string", "index" : "not_analyzed"}, 
      "name" : {"type" : "string"}, 
      "email" : {"type" : "string", "index" : "not_analyzed", "null_value" : "NOEMAILAVAILABLE"} 
     } 
    } 
} 

處理這種潛在的方式羅列如下:http://www.elasticsearch.org/guide/reference/mapping/core-types.html