Hi everyone!
I'm struggling with generating a query that fits the following scenario:
- A single index with two types:
purchaseandsearch. - Given a multi-bucket metric (say,
histogram), calculate for each bucket the ratio or quotient of the count of documents on both types.
So far, I've managed to put together something like this:
{
"aggs": {
"conversion_rate_m": {
"filters": {
"filters": {
"abandon": {
"bool": {
"must": {
"type": {
"value": "search"
}
}
}
},
"conversion": {
"bool": {
"must": {
"type": {
"value": "purchase"
}
}
}
}
}
},
"aggs": {
"conversion_abandon": {
"cardinality": {
"field": "_uid"
}
}
}
},
"conversion_rate_m_metadata": {
"bucket_script": {
"buckets_path": {
"convert": "conversion_rate_m> ?", // <-- No idea here
"abandon": "conversion_rate_m> ?" // <-- ...nor here
},
"script": "convert / abandon"
}
}
}
}
However, I failed to guess which are the actual values for buckets_path that would please Elasticsearch. Tried many possible combinations, up to a point where I was just guessing things up. To make matters worse, documentation is incredibly vague and obscure on the topic.
I also tried omitting the cardinality agg altogether and just make use of the doc_count value produced by each of the filters, but no avail. Stumbled upon the same problem: generating a proper bucket_path for the script to work.
So, which value should I use? Or maybe suggest a better way of going about this?
Thank you very much.