我在 AWS Cloudsearch 中有以下类型的记录:
{
"records":[
{
"id": "1",
"fields": {
"org_id": "2424",
"table_id": "2797",
"status": "Current",
"auth_level": "[ \"PLATINUM PLUS\" ]",
"country_code": "IN"
}
},
{
"id": "2",
"fields": {
"org_id": "333",
"table_id": "2751",
"status": "Current",
"auth_level": "[ \"AUTHORIZED\" , \"PLATINUM PLUS\" ]",
"country_code": "IN"
}
},
{
"id": "3",
"fields": {
"org_id": "444",
"table_id": "2797",
"status": "Current",
"auth_level": "[ \"AUTHORIZED\" , \"PLATINUM PLUS\" ]",
"country_code": "US"
}
},
{
"id": "4",
"fields": {
"org_id": "555",
"table_id": "277",
"status": "Current",
"auth_level": "[ \"PLATINUM\" ]",
"country_code": "UK"
}
}
]
}
现在我需要过滤掉
auth_type
只包含一个值的所有记录,即PLATINUM PLUS
。目前我正在使用以下查询来获取结果,但不确定如何进行此过滤。
"(and country_code:'IN' (or (term field=auth_level 'PLATINUM') ))"
这个查询将在那里,我想添加到这个查询中,以便响应包含 Platinum Plus 结果,如果这是指定的唯一身份验证级别。这个怎么做 ?我在这里使用 Javascript SDK 并为查询指定了
Lucene
类型。
对于上述记录,我需要一个查询,它给出不包含第一项的响应,因为它只有一个授权级别值,并且该值是 Platinum Plus。
要过滤掉 auth_level 字段中只有一个值且该值为“PLATINUM PLUS”的所有记录,您可以使用以下查询:
(and country_code:'IN' (not (and (range field=auth_level {, "PLATINUM PLUS"}) (range field=auth_level {"PLATINUM PLUS",}))))
此查询使用两个范围过滤器来排除 auth_level 字段中只有一个值且该值为“PLATINUM PLUS”的记录。第一个范围过滤器检查 auth_level 字段没有值或只有一个值小于或等于“PLATINUM PLUS”的记录。第二个范围过滤器检查 auth_level 字段没有值或只有一个大于或等于“PLATINUM PLUS”的值的记录。通过将这两个范围过滤器与“和”运算符组合,我们可以排除 auth_level 字段中只有一个值且该值为“PLATINUM PLUS”的记录。
这是将上述过滤器与您现有的查询相结合的完整查询:
(and country_code:'IN' (not (and (range field=auth_level {, "PLATINUM PLUS"}) (range field=auth_level {"PLATINUM PLUS",}))) (or (term field=auth_level 'PLATINUM')))
此查询应返回 country_code 等于“IN”、auth_level 包含“PLATINUM”或具有多个 auth_levels 的所有记录,但不包括 auth_level 字段中只有一个值且该值为“PLATINUM PLUS”的记录。