假设我有4个查询:A,B,C,D。 我想要做的是对于查询A的给定结果集来计算每个其他查询的结果集的交集计数。计算给定结果集上查询的文档数
基本上我想要数A AND B
,A AND C
和A AND D
但我不想每次重新计算A
。 我使用ES V2.4
实例 - 比方说,我有以下映射
{
"mappings": {
"doc": {
"properties": {
"type": {
"type": "string"
},
"gender": {
"type": "string"
},
"color": {
"type": "string"
},
"material": {
"type": "string"
}
}
}
}
}
而且我A
查询匹配是Shirt
类型,这样的所有项目索引:
{
"query": {
"match": {
"type": "Shirt"
}
}
}
现在从结果集(“所有类型的衬衫项目”)我想要得到的数字也是“蓝色”,或者是“男性” 我可以通过创建分开查询:
{
"query": {
"bool": {
"must": [
{
"match": {
"type": "Shirt"
}
},
{
"match": {
"color": "Blue"
}
}
]
}
}
}
而且
{
"query": {
"bool": {
"must": [
{
"match": {
"type": "Shirt"
}
},
{
"match": {
"gender": "Male"
}
}
]
}
}
}
但是这将导致搜索type: "Shirt"
每个我真的想避免的查询。
更新:我已经找到了我一直在寻找 - “过滤器”聚集 - 这样我就可以建立我的查询如下:
{
"query": {
"match": {
"type": "Shirt"
}
},
"aggs": {
"gender_male": {
"filter": {
"match": {
"gender": "Male"
}
}
},
"color_blue": {
"filter": {
"match": {
"color": "Blue"
}
}
}
}
}
能否请您用一个例子更好地解释一下。 –
@HatimStovewala更新,以示例 –
您只需要计数? –