I want to aggregate the count for 2 fields in Elasticsearch. The first field is transporter1 and the second field is transporter2. How I want to display my results are as follows:
Uber: 500
Lyft: 220
Taxi: 150
So for example, transporter1 might be Uber and another field might be Lyft. If in one document, transporter2 is Uber and transporter1 is Lyft, then both Uber and Lyft will have a count of 2 since they appear as transporter1 in one document and transporter2 in another.
I tried creating a query for this, but the results are not what I want.
{
"query":{
"match":{
"market": "TEST"
}
},
"aggs": {
"group_by_transporter": {
"terms": {
"field": "transporter1"
},
"aggs": {
"group_by_transporter": {
"terms": {
"field": "transporter2"
}
}
}
}
}
}
How do I make it so that I can get the market share of transporters?