我是elasticsearch和nosql文档模型的新手。
在elasticsearch中,字段为null的最佳实践是什么?
我们应该声明它为null还是完全忽略它?
示例:email字段
[{
id:1,
name:"John",
email:"userone@erj.com"
},
{
id:2,
name:"David",
email:null
},
{
id:3,
name:"Tony"
}]
如何处理null字段完全取决于您。默认情况下,ES将完全忽略null字段。如果您愿意,您也可以在文档的映射中为null字段指定一个默认值。
映射的例子:
{
"_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