You can use the eval command to selectively create a field depending on its value:
... | eval car=if(match(product,"(?i)^(mercedes|ferrari|porsche)$"),null()) | eval fruit=if(match(product,"(?i)^(apple|banana)$"),null()) | stats values(car) values(fruit)
You can use the split-by clause in the stats command, to create an aggregated value for each year:
... | eval year=strftime(_time,"%Y") | stats mean(somefield) by year
Edit, to answer the question in the comment: yes, you can do something like this
... | eval type=case(match(product,"(?i)^(mercedes|ferrari|porsche)$"),"car",match(product,"(?i)^(apple|banana)$"),"fruit") | eval year=strftime(_time,"%Y") | chart mean(somefield) over type by year
... View more