我们在 ElasticSearch 查询中发现了一个奇怪的行为。我们有两种类型,它们作为父母(申请人)和孩子(附件)连接在一起。
父表的映射:
{
"Applicant": {
"properties": {
"Name": {
"type": "string"
},
"Focus": {
"type": "string"
},
"KnowHowClassification": {
"type": "string"
}
}
}
}
子表的映射:
{
"Attachments_Applicant": {
"_parent": {
"type": "Applicant"
},
"properties": {
"File": {
"type": "attachment"
}
}
}
}
我们需要查询两个表中的所有字段以找到某些关键字并返回父文档。为此,我们使用以下查询:
{
"from": 0,
"size": 100,
"query": {
"bool": {
"should": [
{
"has_child": {
"type": "Attachments_Applicant",
"query": {
"bool": {
"must": [
{
"query_string": {
"query": “{{search}}”
}
}
]
}
}
}
},
{
"query_string": {
"query": “{{search}}”
}
}
]
}
}
}
如果我们搜索“java css”(不带引号),我们会找到包含其中一个或两个术语的文档。
如果我们搜索“+java +css”(不带引号),我们只会在其中一个表中找到同时包含这两个术语的文档。如果其中一个条款在申请人表中,另一个在附件表中,则这些文件不会被退回。
有没有办法用 query_string 查询所有字段父子表,其中包含必需的术语(+)?