[英]Creating Dynamic Facets in Elasticsearch
I want to dynamically create facetts for a nested type that has dynamic attributes. 我想为具有动态属性的嵌套类型动态创建facetts。
Suppose these articles are in my Index and that I'm searching for name and brand: 假设这些文章在我的索引中,并且我正在搜索名称和品牌:
{
name: iPhone 16GB
brand: Apple
type: Smartphone
attributes: {
Color: White
}
}
{
name: iPad
brand: Apple
type: Tablet
attributes: {
Color: Black
}
}
{
name: Cruzer USB 16GB
brand: SanDisk
type: USB-Stick
attributes: {
Color: Black
Capacity: 16GB
USB-Standard: USB 2.0
}
}
{
name: Cruzer USB 16GB
brand: SanDisk
type: USB-Stick
attributes: {
Color: Red
Capacity: 16GB
USB-Standard: USB 3.0
}
}
Now, if I'm searching for 'Apple' I want to have a search result that has the following facets: 现在,如果我要搜索“ Apple”,我希望搜索结果具有以下方面:
Brand:
Apple 2
Type:
Smartphone 1
Tablet 1
Color:
Black 1
White 1
A search for '16GB' should include those facets: 搜索“ 16GB”应包括以下方面:
Brand:
Apple 1
SanDisk 2
Type:
Smartphone 1
USB-Stick 2
Color:
Black 1
White 1
Red 1
Capacity:
16GB 2
USB-Standard:
USB 3.0 1
USB 2.0 2
Likewise, every article can have arbitrary attributes. 同样,每篇文章都可以具有任意属性。
The facetted search for brand and type is easy, but how could i do it for the attrubutes? 品牌和类型的多面搜索很容易,但是我该如何为attrubuts做呢? Is this even possible with elasticsearch?
使用Elasticsearch甚至可能吗?
I hope you can unterstand what i mean... 我希望你能理解我的意思。
Try with below 请尝试以下
POST _search
{
"query": {
"query_string": {
"query": "Apple"
}
},
"facets": {
"tags": {
"terms": {
"fields": ["name","brand","type","attributes.Color"]
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.