我将PHP MySQL应用程序转换为Elasticsearch, 这是我的PHP MySQL查询以及如何将此查询写入Elasticseach(版本5.5)
我尝试编写聚合,但结果与旧的MySQL结果计数不匹配。
SELECT COUNT(DISTINCT offerName, `OfferID`, `duration`, `price`, `numChannels`, providerName) AS "totalRecords" FROM `video` WHERE `active` = 'Y'
这是我的Elasticsearch查询:
{
"size": 0,
"query":
{ "bool": {
"should": [
{ "match": { "active": "Y" }}
]
}
},
"aggs": {
"count_by_OfferID": {
"terms": {
"field": "offerID"
}
},
"count_by_offerName":{
"terms": {
"field": "offerName"
}
},
"count_by_duration":{
"terms": {
"field": "duration"
}
},
"count_by_price":{
"terms": {
"field": "price"
}
},
"count_by_downloadSpeed":{
"terms": {
"field": "downloadSpeed"
}
},
"count_by_numChannels":{
"terms": {
"field": "numChannels"
}
},
"count_by_providerName":{
"terms": {
"field": "providerName"
}
}
}
}
答案 0 :(得分:1)
也许您应该修改映射,以便更有效地获得答案,但Elasticsearch的{{1}}称为DISTINCT COUNT
聚合,它支持ad-hoc scripting。我希望我能正确理解你的问题。
基数指标支持脚本编写,但是由于需要动态计算哈希值,因此会有明显的性能影响。