-
非空匹配
返回在原始字段中至少有一个非空值的文档:
比如下面的字段都因为有值而被匹配
{ "user": "jane" }
{ "user": "" } ①
{ "user": "-" } ②
{ "user": ["jane"] }
{ "user": ["jane", null ] } ③
demo比如:匹配所有ownerId 的值
{
"query": {
"bool": {
"must": [
{
"term": {
"businessId": "10"
}
},
{
"exists" : {
"field" : "ownerId"
}
}
],
"should": [],
"filter": []
}
},
"from": 0,
"size": 10,
"sort": []
}
返回值:看ownerId
{
"took": 79,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2977535,
"max_score": 2,
"hits": [
{
"_index": "csc-pacific-case-monitor",
"_type": "case-monitor",
"_id": "36501315",
"_score": 2,
"_source": {
"caseId": "36501315",
"addTime": 1537100564000,
"caseTypeId": "776",
"closerId": "17821",
"closeTime": 1537100564000,
"contactNumber": "[\"\",\"17764105080\"]",
"content": "无人接单",
"creatorId": "17821",
"customerId": "115962670",
"customerType": "1001",
"deadline": 1537102364000,
"feedbackTime": null,
"businessId": "10",
"businessName": null,
"fourthCategoryId": null,
"fifthCategoryId": null,
"ownerId": "17821",
"managerId": "17821",
"questionId": "9984",
"questionReasonId": null,
"orderTypeId": "8",
"source": "2",
"statusId": "2",
"subSource": "-1",
"questionTypeId": "2767",
"updateTime": 1537100564000,
"startTime": 1537100564000,
"priorityId": "7",
"updaterId": "17821",
"memo": null,
"flowId": "533",
"nodeId": "67266",
"lifeCycle": "1",
"latest_main_scn": 4900984951192,
"latest_main_es_update_time": 1537100564740,
"level_1": "1",
"level_2": "3",
"level_3": "6",
"level_4": "11",
"level_5": "621",
"level_6": "622",
"departmentId": 622
}
}
]
}
}
-
空值匹配
这些文档将不会被上面的查询匹配到:
|
①这个字段没有任何值。
②至少需要一个 non-null 非空值。
③ user 字段完全丢失。
下面的demo,是匹配了上面的情况
{
"query": {
"bool": {
"must": [
{
"term": {
"businessId": "10"
}
}
],
"must_not": [
{
"exists" : {
"field" : "ownerId"
}
}
],
"should": [],
"filter": []
}
},
"from": 0,
"size": 10,
"sort": []
}
返回结果如下
{
"took": 52,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 88888,
"max_score": 1,
"hits": [
{
"_index": "csc-pacific-case-monitor",
"_type": "case-monitor",
"_id": "36499324",
"_score": 1,
"_source": {
"caseId": "36499324",
"addTime": 1537099751000,
"caseTypeId": "100",
"closerId": "0",
"closeTime": 1537100911000,
"contactNumber": null,
"content": null,
"creatorId": "0",
"customerId": "340327304",
"customerType": "1001",
"deadline": 1537186151000,
"feedbackTime": null,
"businessId": "10",
"businessName": null,
"fourthCategoryId": null,
"fifthCategoryId": null,
"ownerId": null,
"managerId": "0",
"questionId": "3962",
"questionReasonId": null,
"orderTypeId": "8",
"source": "20",
"statusId": "2",
"subSource": "301",
"questionTypeId": "2770",
"updateTime": 1537100911000,
"startTime": 1537099751000,
"priorityId": "5",
"updaterId": "0",
"memo": null,
"flowId": "118",
"nodeId": "67975",
"lifeCycle": "1",
"latest_main_scn": 4901075798318,
"latest_main_es_update_time": 1537100911065
}
},
{
"_index": "csc-pacific-case-monitor",
"_type": "case-monitor",
"_id": "36509054",
"_score": 1,
"_source": {
"caseId": "36509054",
"addTime": 1537104132000,
"caseTypeId": "100",
"closerId": "0",
"closeTime": 1537105346000,
"contactNumber": null,
"content": null,
"creatorId": "0",
"customerId": "218704968",
"customerType": "1001",
"deadline": 1537190532000,
"feedbackTime": null,
"businessId": "10",
"businessName": null,
"fourthCategoryId": null,
"fifthCategoryId": null,
"ownerId": null,
"managerId": "0",
"questionId": "3962",
"questionReasonId": null,
"orderTypeId": "8",
"source": "20",
"statusId": "2",
"subSource": "301",
"questionTypeId": "2770",
"updateTime": 1537105346000,
"startTime": 1537104132000,
"priorityId": "5",
"updaterId": "0",
"memo": null,
"flowId": "118",
"nodeId": "67975",
"lifeCycle": "1",
"latest_main_scn": 4905281330698,
"latest_main_es_update_time": 1537105346278
}
}
]
}
}