想象一下,我有一个文档,如下所示:
{
"Title": "Smartphones in United Kingdom",
"Text": "A huge text about the topic",
"CategoryTags": [
{
"CategoryID": 1,
"CategoryName": "Smartphone"
},
{
"CategoryID": 2,
"CategoryName": "Apple"
},
{
"CategoryID": 3,
"CategoryName": "Samsung"
}
],
"GeographyTags": [
{
"GeographyID": 1,
"GeographyName": "Western Europe"
},
{
"GeographyID": 2,
"GeographyName": "United Kingdom"
}
]
}
CategoryTags
和GeographyTags
存储为嵌套的子文档。
我正在寻找"苹果联合王国"在我的搜索栏中。如果同时具有匹配的类别和地理位置,我如何提出可以提升此文档的查询?
我在考虑multi_match查询,但我还没弄清楚如何在这里处理嵌套文档...
我在考虑嵌套必须进入应该声明。那会有意义吗?
POST /_search
{
"template": {
"size": "50",
"_source": {
"include": "Title"
},
"query": {
"filtered": {
"query": {
"bool": {
"minimum_number_should_match": "2<50%",
"must": [
{
"match": {
"Text": {
"query": "{{SearchPhrase}}"
}
}
}
],
"should": [
{
"match": {
"Title": {
"query": "{{SearchPhrase}}",
"type": "phrase",
"boost": "20"
}
}
},
{
"bool": {
"must": [
{
"nested": {
"path": "CategoryTags",
"query": {
"match": {
"CategoryTags.CategoryName": "{{SearchPhrase}}"
}
}
}
},
{
"nested": {
"path": "GeographyTags",
"query": {
"match": {
"GeographyTags.GeographyName": "{{SearchPhrase}}"
}
}
}
}
]
}
}
]
}
}
}
}
}
}