{
"multi_match": {
"query": "TEST",
"fields": [
"description.regexkeyword^1.0",
"logical_name.regexkeyword^1.0",
"logical_table_name.regexkeyword^1.0",
"physical_name.regexkeyword^1.0",
"presentation_name.regexkeyword^1.0",
"table_name.regexkeyword^1.0"
],
"type": "best_fields",
"operator": "AND",
"slop": 0,
"prefix_length": 0,
"max_expansions": 50,
"lenient": false,
"zero_terms_query": "NONE",
"boost": 1
}
}
有一个字段
edited_description
,如果万一文档中有edited_description exists
,则考虑edited_description.regexkeyword^1.0
,否则请考虑描述,即description.regexkeyword^1.0
。
最佳答案
您无法在multi_match查询中定义if条件。但是,您可以做的是用另一种方式重新查看问题陈述。我可以重新看一下,如果edited_description
和description
都存在,则edited_description
字段中的匹配项应被赋予更高的优先级。
这可以通过为edited_description
字段设置更高的提升值来实现。
{
"multi_match": {
"query": "TEST",
"fields": [
"description.regexkeyword^1.0",
"edited_description.regexkeyword^1.2",
"logical_name.regexkeyword^1.0",
"logical_table_name.regexkeyword^1.0",
"physical_name.regexkeyword^1.0",
"presentation_name.regexkeyword^1.0",
"table_name.regexkeyword^1.0"
],
"type": "best_fields",
"operator": "AND",
"slop": 0,
"prefix_length": 0,
"max_expansions": 50,
"lenient": false,
"zero_terms_query": "NONE",
"boost": 1
}
}
这将导致在
edited_description
中具有匹配项的文档排名更高。您可以根据需要调整提升值。
关于elasticsearch - 我是ES新手,在ES中有一个多匹配查询,并且想根据其可用性考虑字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61878527/