是的,你可以这样做。索引数组,然后正常使用构面。
让我们看看完整的例子。您有以下文件:
{
"Name": "John",
"FavoriteAnimals": [
"Cats",
"Dogs",
"Snails"
],
"@metadata": {
"@collection": "Kids"
}
}
{
"Name": "Jane",
"FavoriteAnimals": [
"Cats",
"Rabits"
],
"@metadata": {
"@collection": "Kids"
}
}
现在,您创建以下索引:
from k in docs.Kids
from animal in k.FavoriteAnimals
select new { Animal = animal }
然后运行这个查询:
from index 'YourIndex'
where startsWith(Animal , 'ca')
select facet('Animal')
结果将是:
{
"Name": "Animal",
"Values": [
{
"Count": 2,
"Range": "cats"
}
]
}
或者,您可以使用此索引:
from k in docs.Kids
select new { k.FavoriteAnimals }
然后运行这个查询:
from index 'YourIndex'
where startsWith(FavoriteAnimals , 'ca')
select facet('FavoriteAnimals')
这里的不同之处在于,您将获得匹配文档的所有匹配项。
所以在这种情况下
{
"Name": "Animal",
"Values": [
{
"Count": 2,
"Range": "cats"
},
{
"Count": 1,
"Range": "dogs"// also, snails, rabbits
}
]
}