Elasticsearch排除PHP中特定字段的搜索



我有这样的数据结构

"id": "162d2df9-16e0-4171-bc54-52f2b3a4a23c",
"uri": "https://local.test.com/abc",
"title": "Geography",
"dateTime": "2022-06-15T09:32:37+00:00",
"type": "Default",
"hcs": "Primary",
"lE": "1",
"otherData": {
"id": "57907298-3945-4654-a75a-7278bcb14399",
"uri": "https://local.test.com/gcsp",
"title": "GCSP"
},
"moreData": {
"id": "48e939c5-c4f3-4cf2-ae2d-8d964682361d",
"uri": "https://local.test.com/xyz",
"title": "Default"
},
"Hierarchy": {
"data": {
"id": "57907298-3945-4654-a75a-7278bcb14399",
"title": "GCSP"
},
"parent": [
{
"id": "162d2df9-16e0-4171-bc54-52f2b3a4a23c",
"title_fs": "Maths",
"hcs_p": "Primary",
"parent": [
{
"id": "ddff7857-f8be-45a1-b41d-aef2207ff66b",
"title_fs": "Civics",
"hcs_p": "Primary",
"parent": [
{
"id": "24d126e2-464b-499b-b2c0-adcd7a7b7728",
"title_fs": "History",
"hcs_p": "Primary",
"parent": [
{
"id": "23a094da-33b8-4960-8daa-8291e6634305",
"title_fs": "Science",
"hcs_p": "Primary",
"parent": [
{
"id": "32de28ab-5bd5-4cd6-9dc9-f9766fcdfab3",
"title_fs": "Subjects",
"hcs_p": "Primary",
"parent": []
}
]
}
]
}
]
}
]
}
]
}

我想排除"Hierarchy"要在结果集中搜索和过滤的数据,那么我如何实现这一点?

我试过了:['bool']['must'][] = ["multi_match"=比;["operator"=比;"这样,,"query"=比;searchTerm美元,"fields"=比;("*","Hierarchy"]

);但不工作

在搜索时没有办法排除特定的字段,但是您可以提供想要搜索的字段列表。

{
"query": {
"multi_match": {
"query": "searchTerm",
"fields": ["field1","field2","field3"], <-- this will search to field1, field2, field3 only
"operator": "and"
}
}
}

如果您想从响应中排除字段,可以在_source中使用excludes参数:

{
"_source": {
"excludes": ["field4"]
}, 
"query": {
"multi_match": {
"query": "searchTerm",
"fields": ["field1","field2","field3"],
"operator": "and"
}
}
}

最新更新