我想在弹性搜索中模拟父子关系并对其执行一些分析工作。我的用例是这样的
我有这样的店主
"_source": {
"shopId": 5,
"distributorId": 4,
"stateId": 1,
"partnerId": 2,
}
现在有这样的子记录(每天):
"_source": {
"shopId": 5,
"date" : 2013-11-13,
"transactions": 150,
"amount": 1980,
}
父项是每个商店的记录,而子项是每个商店每天进行的交易。现在我想做一些复杂的查询,比如
找出过去 30 天内每天的总交易量,其中经销商为 5
POST /newdb/shopsDaily/_search
{
"query": {
"match_all": {}
},
"filter": {
"has_parent": {
"type": "shop",
"query": {
"match": {
"distributorId": "5"
}
}
}
},
"facets": {
"date": {
"histogram": {
"key_field": "date",
"value_field": "transactions",
"interval": 100
}
}
}
}
但是我得到的结果没有考虑我应用的过滤。
所以我将查询更改为:
POST /newdb/shopDaily/_search
{
"query": {"filtered": {
"query": {"match_all": {}},
"filter": { "has_parent": {
"type": "shop",
"query": {"match": {
"distributorId": "13"
}}
}}
}},
"facets": {
"date": {
"histogram": {
"key_field": "date",
"value_field": "transactions",
"interval": 100
}
}
}
}
然后最终的直方图方面将过滤计入计数。
因此,当我浏览时,虽然我发现这是由于使用filtered
(只能在查询子句内部使用而不是在 like 外部使用filter
)而不是filter
,但它也提到要进行快速搜索,您应该使用filter
. 像我在第二步中所做的那样搜索(当我使用filtered
而不是filter
)会影响弹性搜索的性能吗?如果是这样,我怎样才能让我的方面尊重过滤器而不影响性能?
谢谢你的时间