Copy curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
{
"mappings": {
"my_type": {
"properties": {
"status_code": {
"type": "keyword",
"null_value": "NULL" #1
}
}
}
}
}
'
curl -XPUT 'localhost:9200/my_index/my_type/1?pretty' -H 'Content-Type: application/json' -d'
{
"status_code": null
}
'
curl -XPUT 'localhost:9200/my_index/my_type/2?pretty' -H 'Content-Type: application/json' -d'
{
"status_code": [] #2
}
'
curl -XGET 'localhost:9200/my_index/_search?pretty' -H 'Content-Type: application/json' -d'
{
"query": {
"term": {
"status_code": "NULL" #3
}
}
}
'
重点
null_value 必须设置成相同类型的参数。例如,一个long 型的字段不能被设置成string 类型的null_value 。
Copy PUT /my_index
{
"mappings": {
"my_type": {
"properties": {
"status_code": {
"type": "keyword"
}
}
}
}
}
PUT /my_index/my_type/1
{
"status_code": null
}
GET /my_index/_search
{
"query": {
"term": {
"status_code": null
}
}
}
Copy {
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "field name is null or empty"
}
],
"type": "illegal_argument_exception",
"reason": "field name is null or empty"
},
"status": 400
}
所以为了解决这个问题,采用一个值来替换null值的情况. 如开始时候的例子,采用"NULL" 字符串采替换null值的情况进行搜索.