我有以下用于样本数据集的elasticsearch术语过滤器。
"filter":{
"type":"and",
"and":[
{
"type":"terms",
"terms":{
"field":"car_registration_no.raw",
"terms":[
"61123",
"61124",
"61125"
]
}
}
]
}
以下是示例结果:
{
"result": [
{
"totalHits": 3,
"hits": [
{
"schemaid": "adef89sesdceasjkmn5dlky6djj7kk189lkdqsc",
"localVersion": 2,
"row": {
"primaryKey": {
"car_registration_no": "61123"
},
"columns": {
"model": "Nissan",
"submodel": "Saloon",
"date_used": 1597017600000
},
"editsVersion": 0
},
"highlight": {}
},
{
"schemaid": "adef89sesdceasjkmn5dlky6djj7kk189lkdqsc",
"localVersion": 2,
"row": {
"primaryKey": {
"car_registration_no": "61124"
},
"columns": {
"model": "Nissan",
"submodel": "Saloon",
"accidents": "1",
"accident_date": "12/12/2019",
"date_used": 1597017600000
},
"editsVersion": 0
},
"highlight": {}
},
{
"schemaid": "adef89sesdceasjkmn5dlky6djj7kk189lkdqsc",
"localVersion": 2,
"row": {
"primaryKey": {
"car_registration_no": "61125"
},
"columns": {
"model": "Nissan",
"submodel": "Saloon",
"date_used": 1597017600000
},
"editsVersion": 0
},
"highlight": {}
}
],
"counts": {},
"nextToken": null
}
]
}
只有一部汽车(编号61124的汽车)发生了事故记录,我如何才能为其他汽车检索空值或空白值?
我已经已位于简称elasticsearch但因为我在这个初学者,我不能够理解如何处理它。因此,预期结果将是我希望看到空字段accidents和accident_date如果没有值,则显示为null或空白,在上面的示例中,car_registration no 61123和61125具有空值,因此我想检索所有字段不论空白值如何。
{
"result": [
{
"totalHits": 3,
"hits": [
{
"schemaid": "adef89sesdceasjkmn5dlky6djj7kk189lkdqsc",
"localVersion": 2,
"row": {
"primaryKey": {
"car_registration_no": "61123"
},
"columns": {
"model": "Nissan",
"submodel": "Saloon",
"accidents": "null",
"accident_date": "null",
"date_used": 1597017600000
},
"editsVersion": 0
},
"highlight": {}
},
{
"schemaid": "adef89sesdceasjkmn5dlky6djj7kk189lkdqsc",
"localVersion": 2,
"row": {
"primaryKey": {
"car_registration_no": "61124"
},
"columns": {
"model": "Nissan",
"submodel": "Saloon",
"accidents": "1",
"accident_date": "12/12/2019",
"date_used": 1597017600000
},
"editsVersion": 0
},
"highlight": {}
},
{
"schemaid": "adef89sesdceasjkmn5dlky6djj7kk189lkdqsc",
"localVersion": 2,
"row": {
"primaryKey": {
"car_registration_no": "61125"
},
"columns": {
"model": "Nissan",
"submodel": "Saloon",
"accidents": "null",
"accident_date": "null",
"date_used": 1597017600000
},
"editsVersion": 0
},
"highlight": {}
}
],
"counts": {},
"nextToken": null
}
]
}
您想要的是能够查看NULL
文档的值,默认情况下这是不可能的,因为NULL
值没有索引和可搜索,请参阅官方NULL_VALUES文档以获取更多信息
空值不能被索引或搜索。当字段设置为null(或空数组或null值的数组)时,将其视为该字段没有值。
但是要实现用例,您需要null_value
在映射中提供参数,同时在对文档建立索引时,如果您没有收到任何值,但在文档中传递了null_value
参数值(如以下完整示例所示)
索引映射
{
"mappings": {
"properties": {
"accidents": {
"type": "keyword",
"null_value": "NULL" --> note this
},
"accidents_date": {
"type": "keyword",
"null_value": "NULL"
},
"car_registration_no" :{
"type" : "keyword"
}
}
}
}
索引样本文档
{
"accidents" : "1",
"accidents_date": "12/12/2019",
"car_registration_no" : "61124"
}
{
"accidents" : "null",
"accidents_date": "null",
"car_registration_no" : "61125"
}
{
"accidents" : "null",
"accidents_date": "null",
"car_registration_no" : "61123"
}
搜索查询
{
"query": {
"terms": {
"car_registration_no": [
"61124",
"61123",
"61125"
],
"boost": 1.0
}
}
}
和预期的搜索结果
"hits": [
{
"_index": "carindex",
"_type": "_doc",
"_id": "1",
"_score": 1.0,
"_source": {
"accidents": "null", --> note this
"accidents_date": "NULL",
"car_registration_no": "61123"
}
},
{
"_index": "carindex",
"_type": "_doc",
"_id": "2",
"_score": 1.0,
"_source": {
"accidents": "1",
"accidents_date": "12/12/2019",
"car_registration_no": "61124"
}
},
{
"_index": "carindex",
"_type": "_doc",
"_id": "3",
"_score": 1.0,
"_source": {
"car_registration_no": "61125"
}
}
]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句