【发布时间】:2020-08-21 04:58:55
【问题描述】:
我正在使用以下查询对象进行多重匹配搜索:
{
_source: [
'baseline',
'cdrp',
'date',
'description',
'dev_status',
'element',
'event',
'id'
],
track_total_hits: true,
query: {
bool: {
filter: [{name: "baseline", values: ["1f.0.1.0", "1f.1.8.3"]}],
should: [
{
multi_match:{
query: "national",
fields: ["cdrp","description","narrative.*","title","cop"]
}
}
]
}
},
highlight: { fields: { '*': {} } },
sort: [],
from: 0,
size: 50
}
我希望在描述或叙述中找到“国家”一词。* 字段,但返回的 2 条记录中只有一条符合我的预期。我正在尝试了解原因。
elasticsearch.config.ts
"settings": {
"analysis": {
"analyzer": {
"search_synonyms": {
"tokenizer": "whitespace",
"filter": [
"graph_synonyms",
"lowercase",
"asciifolding"
],
}
}
}
},
"mappings": {
"properties": {
"description": {
"type": "text",
"analyzer": "search_synonyms"
},
"narrative": {
"type":"object",
"properties":{
"_all":{
"type": "text",
"analyzer": "search_synonyms"
}
}
},
}
}
【问题讨论】:
-
也分享示例文档。
-
@shAkur multi_match 查询是 should 子句的一部分,因此只会影响评分。所有文件将被退回。具有“国家”的文件将获得更高的分数。如果你打算过滤 "national" ,你应该把它移到 filter 子句下
-
我希望过滤器与描述和叙述。* 字段进行“与”运算,因此“国家”一词应位于其中一个文本字段中。在过滤器中移动 multi_match 对象可以解决问题,还是使用 must 会更好?
标签: elasticsearch indexing filter analyzer