elasticsearch Elasticsearch:查找包含数组字段的所有文档,数组字段可以为空或非空
请在我的elasticsearch 7.7.0中找到以下示例文档。如何构建优化查询以获取包含数组字段的所有文档。如您所见,有些文档没有此字段,有些文档的值为null。需要获取此字段为空数组或数组中有某些项的文档。需要删除缺少字段或字段为空的文档 示例文档:
elasticsearch Elasticsearch:查找包含数组字段的所有文档,数组字段可以为空或非空,
elasticsearch,
elasticsearch,请在我的elasticsearch 7.7.0中找到以下示例文档。如何构建优化查询以获取包含数组字段的所有文档。如您所见,有些文档没有此字段,有些文档的值为null。需要获取此字段为空数组或数组中有某些项的文档。需要删除缺少字段或字段为空的文档 示例文档: [ { "_index" : "test", "_type" : "_doc", "_id"
[
{
"_index" : "test",
"_type" : "_doc",
"_id" : "5",
"_score" : 1.0,
"_source" : {
"severity" : 5,
"problemInvestigations" : [
{
"Request ID01" : "PBI000000000001",
"Request Description01" : "PBI000000000001: Test 1"
},
{
"Request Description02" : "PBI000000000002: Test 2",
"Request ID02" : "PBI000000000002"
},
{
"Request ID03" : "PBI000000000003",
"Request Description03" : "PBI000000000003: Test 3"
},
{
"Request ID01" : "PBI000000000016",
"Request Description01" : "PBI000000000016: Test 3"
}
],
"Summary*" : "Bitlocker encryption log in issue",
"tenantId" : "tenant",
"Operational Categorization Tier 2" : "Software",
"Incident Number" : "PDINC0003203145"
}
},
{
"_index" : "test",
"_type" : "_doc",
"_id" : "92",
"_score" : 1.0,
"_source" : {
"severity" : 5,
"problemInvestigations" : [
{
"Request ID01" : "PBI000000000016",
"Request Description01" : "PBI000000000016: Test 3"
}
],
"Summary*" : "Bitlocker encryption log in issue",
"tenantId" : "tenant",
"Operational Categorization Tier 2" : "Software",
"Incident Number" : "PDINC0003203145"
}
},
{
"_index" : "test",
"_type" : "_doc",
"_id" : "107",
"_score" : 1.0,
"_source" : {
"severity" : 5,
"problemInvestigations" : [ ],
"Summary*" : "Bitlocker encryption log in issue",
"tenantId" : "tenant",
"Operational Categorization Tier 2" : "Software",
"Incident Number" : "PDINC0003203145"
}
},
{
"_index" : "test",
"_type" : "_doc",
"_id" : "134",
"_score" : 1.0,
"_source" : {
"severity" : 5,
"problemInvestigations" : null,
"Summary*" : "Bitlocker encryption log in issue",
"tenantId" : "tenant",
"Operational Categorization Tier 2" : "Software",
"Incident Number" : "PDINC0003203145"
}
},
{
"_index" : "test",
"_type" : "_doc",
"_id" : "135",
"_score" : 1.0,
"_source" : {
"severity" : 5,
"Summary*" : "Bitlocker encryption log in issue",
"tenantId" : "tenant",
"Operational Categorization Tier 2" : "Software",
"Incident Number" : "PDINC0003203145"
}
}
]
我正在寻找以下文件作为结果的一部分:
预期结果:
[
{
"_index" : "test",
"_type" : "_doc",
"_id" : "5",
"_score" : 1.0,
"_source" : {
"severity" : 5,
"problemInvestigations" : [
{
"Request ID01" : "PBI000000000001",
"Request Description01" : "PBI000000000001: Test 1"
},
{
"Request Description02" : "PBI000000000002: Test 2",
"Request ID02" : "PBI000000000002"
},
{
"Request ID03" : "PBI000000000003",
"Request Description03" : "PBI000000000003: Test 3"
},
{
"Request ID01" : "PBI000000000016",
"Request Description01" : "PBI000000000016: Test 3"
}
],
"Summary*" : "Bitlocker encryption log in issue",
"tenantId" : "tenant",
"Operational Categorization Tier 2" : "Software",
"Incident Number" : "PDINC0003203145"
}
},
{
"_index" : "test",
"_type" : "_doc",
"_id" : "92",
"_score" : 1.0,
"_source" : {
"severity" : 5,
"problemInvestigations" : [
{
"Request ID01" : "PBI000000000016",
"Request Description01" : "PBI000000000016: Test 3"
}
],
"Summary*" : "Bitlocker encryption log in issue",
"tenantId" : "tenant",
"Operational Categorization Tier 2" : "Software",
"Incident Number" : "PDINC0003203145"
}
},
{
"_index" : "test",
"_type" : "_doc",
"_id" : "107",
"_score" : 1.0,
"_source" : {
"severity" : 5,
"problemInvestigations" : [ ],
"Summary*" : "Bitlocker encryption log in issue",
"tenantId" : "tenant",
"Operational Categorization Tier 2" : "Software",
"Incident Number" : "PDINC0003203145"
}
}
]
我在下面运行查询,但没有得到任何文档。请建议
GET test/_search
{
"query": {
"bool": {
"filter": {
"script": {
"script": """
if (doc.containsKey('problemInvestigations') && doc['problemInvestigations'].values.length >= 0) {
return true;
}else{
return false;
}
"""
}
}
}
}
}