gpt4 book ai didi

php - 如何将 mysql 不同查询写入 Elasticsearch

转载 作者:行者123 更新时间:2023-11-29 10:40:42 25 4
gpt4 key购买 nike

我正在将 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"
}
}
}

}

最佳答案

也许您应该修改您的映射,以便更有效地获得答案,但 Elasticsearch 的 DISTINCT COUNT 称为 基数 聚合,并且它支持临时 scripting 。我希望我正确理解了你的问题。

The cardinality metric supports scripting, with a noticeable performance hit however since hashes need to be computed on the fly.

关于php - 如何将 mysql 不同查询写入 Elasticsearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45540281/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com