我有一个网页,根据用户对问题的回答显示汽车列表,在导航到汽车页面之前,他/她应该回答这些问题。换句话说,我有一个规则,规定哪些车应该/不应该向用户显示。例如:只有当用户用“黑色”回答“你最喜欢什么颜色?”或用选项“18”回答“你多大了?”时,才可以使用宝马汽车。因此,当用户导航到cars页面时,app逻辑通过将用户选择的答案与规则中配置的答案进行匹配来评估配置的cars规则。
为了让用户在该页面上进行快速搜索,将cars及其规则放入elasticsearch中,elasticsearch由3个节点组成, version 6.2.4
汽车与其规则之间的关系定义为连接类型
"carRulesRelationship": {
"type": "join",
"eager_global_ordinals": true,
"relations": {
“car”: [
“carAvailability"
]
}
}
car文档示例:
"_type": "doc",
"_id": "233492",
"_source": {
"id0": 233492,
"name": "BMW",
"carRulesRelationship": "car",
"status": "active",
"updatedate23": "2020-10-01T01:00:16.280Z",
"@timestamp": "2020-10-19T11:19:29.865Z"
}
规则示例:
{
"_type": "doc",
"_id": "233492-18474",
"_routing": "233492",
"found": true,
"_source": {
"ruleType": "carAvailability",
"ruleUpdatedDate": "2020-10-07T00:09:42.993Z",
"carAvailability": {
"visible": true,
"userMessage": "You are no longer eligible for this car."
},
"ruleName": "BMW rule",
"ruleConditionalOperator": "or",
"requiredMatches": 4,
"ruleCreatedDate": "2020-08-19T15:42:31.327Z",
"questionDetailsConditionalRules": [
{
"questionDetailId": 13994034
},
{
"questionDetailId": 13994031
},
{
"questionDetailId": 13994035
},
{
"questionDetailId": 13994024
}
],
"ruleId": 18474,
"carRulesRelationship": {
"name": "carAvailability",
"parent": "233492"
}
}
}
根据用户选择的答案ID,仅返回用户应能看到的汽车的搜索查询:
{
"from": 0,
"size": 100,
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "*",
"fields": [
"searchfield^1.0"
],
"type": "best_fields",
"default_operator": "and",
"max_determinized_states": 10000,
"enable_position_increments": true,
"fuzziness": "0",
"fuzzy_prefix_length": 0,
"fuzzy_max_expansions": 1,
"phrase_slop": 0,
"escape": false,
"auto_generate_synonyms_phrase_query": false,
"fuzzy_transpositions": false,
"boost": 1.0
}
}
],
"filter": [
{
"terms": {
"status": [
"active",
"closed"
],
"boost": 1.0
}
}
],
"must_not": [
{
"has_child": {
"query": {
"bool": {
"filter": [
{
"term": {
"carAvailability.visible": {
"value": false,
"boost": 1.0
}
}
},
{
"term": {
"ruleConditionalOperator": {
"value": "and",
"boost": 1.0
}
}
},
{
"terms_set": {
"questionDetailsConditionalRules.questionDetailId": {
"terms": [
13994021, 13994032, 13994042, 13994040, 13993960, 13993983, 13994024
],
"minimum_should_match_field": "requiredMatches",
"boost": 1.0
}
}
}
],
"adjust_pure_negative": true,
"boost": 1.0
}
},
"type": "carAvailability",
"score_mode": "none",
"min_children": 0,
"max_children": 2147483647,
"ignore_unmapped": false,
"boost": 1.0
}
},
{
"has_child": {
"query": {
"bool": {
"filter": [
{
"term": {
"carAvailability.visible": {
"value": false,
"boost": 1.0
}
}
},
{
"term": {
"ruleConditionalOperator": {
"value": "or",
"boost": 1.0
}
}
},
{
"terms": {
"questionDetailsConditionalRules.questionDetailId": [
13994021, 13994032, 13994042, 13994040, 13993960, 13993983, 13994024
],
"boost": 1.0
}
}
],
"adjust_pure_negative": true,
"boost": 1.0
}
},
"type": "carAvailability",
"score_mode": "none",
"min_children": 0,
"max_children": 2147483647,
"ignore_unmapped": false,
"boost": 1.0
}
},
{
"has_child": {
"query": {
"bool": {
"filter": [
{
"term": {
"carAvailability.visible": {
"value": true,
"boost": 1.0
}
}
},
{
"term": {
"ruleConditionalOperator": {
"value": "and",
"boost": 1.0
}
}
},
{
"bool": {
"must_not": [
{
"terms_set": {
"questionDetailsConditionalRules.questionDetailId": {
"terms": [13994021, 13994032, 13994042, 13994040, 13993960, 13993983, 13994024],
"minimum_should_match_field": "requiredMatches",
"boost": 1.0
}
}
}
],
"adjust_pure_negative": true,
"boost": 1.0
}
}
],
"adjust_pure_negative": true,
"boost": 1.0
}
},
"type": "carAvailability",
"score_mode": "none",
"min_children": 0,
"max_children": 2147483647,
"ignore_unmapped": false,
"boost": 1.0
}
},
{
"has_child": {
"query": {
"bool": {
"filter": [
{
"term": {
"carAvailability.visible": {
"value": true,
"boost": 1.0
}
}
},
{
"term": {
"ruleConditionalOperator": {
"value": "or",
"boost": 1.0
}
}
},
{
"bool": {
"must_not": [
{
"terms": {
"questionDetailsConditionalRules.questionDetailId": [13994021, 13994032, 13994042, 13994040, 13993960, 13993983, 13994024],
"boost": 1.0
}
}
],
"adjust_pure_negative": true,
"boost": 1.0
}
}
],
"adjust_pure_negative": true,
"boost": 1.0
}
},
"type": "carAvailability",
"score_mode": "none",
"min_children": 0,
"max_children": 2147483647,
"ignore_unmapped": false,
"boost": 1.0
}
}
],
"adjust_pure_negative": true,
"boost": 1.0
}
}
}
cars和rules数据更新过程:通过logstash在es中刷新cars及其规则,logstash从mssqldb获取数据并输出到es。配置了两个管道:
cars pipeline-每3分钟运行一次,并重新索引es中的所有cars(对应于3个env-qa、stg、prod的3个索引,每个索引的cars数为177k),无论是否更新。
规则管道-每2分钟运行一次,仅获取自上一次logstash循环迭代以来的新的/更新的数据库记录。
问题:一些用户告知他们看到了他们不应该看到的汽车,因为他们没有选择汽车规则要求的答案,例如: the car rule requires answer with Id 13994028 to be visible for user.
对这些用户运行上面的搜索查询总是返回正确的车集,而不会返回错误的车集。只有少数用户偶尔会遇到这个问题,我仍然无法理解根本原因。
问:在logstash重新索引car文档时,是否可能临时中断了car和规则文档之间的父/子关系。所以用户进入汽车文档重新索引的时间窗口,可以看到错误的汽车?
暂无答案!
目前还没有任何答案,快来回答吧!