Running version 5.4 of Elasticsearch.
With this mapping:
PUT pizzas
{
"mappings": {
"pizza": {
"properties": {
"name": {
"type": "keyword"
},
"types": {
"type": "nested",
"properties": {
"topping": {
"type": "keyword"
},
"base": {
"type": "keyword"
}
}
}
}
}
}
}
And this data:
PUT pizzas/pizza/1
{
"name": "meat",
"types": [
{
"topping": "bacon",
"base": "normal"
},
{
"topping": "bacon",
"base": "sour dough"
},
{
"topping": "pepperoni",
"base": "sour dough"
}
]
}
If I run this query:
GET pizzas/_search
{
"query": {
"nested": {
"path": "types",
"query": {
"bool": {
"filter": {
"term": {
"types.topping": "bacon"
}
}
}
}
}
}
}
I get:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0,
"hits": [
{
"_index": "pizzas",
"_type": "pizza",
"_id": "1",
"_score": 0,
"_source": {
"name": "meat",
"types": [
{
"topping": "bacon",
"base": "normal"
},
{
"topping": "bacon",
"base": "sour dough"
},
{
"topping": "pepperoni",
"base": "sour dough"
}
]
}
}
]
}
}
But what I really want for my hits are:
"hits": [
{
"_index": "pizzas",
"_type": "pizza",
"_id": "1",
"_score": 0,
"_source": {
"name": "meat",
"types": [
{
"topping": "bacon",
"base": "normal"
}
]
}
},
{
"_index": "pizzas",
"_type": "pizza",
"_id": "1",
"_score": 0,
"_source": {
"name": "meat",
"types": [
{
"topping": "bacon",
"base": "sour dough"
}
]
}
}
]
I want to do this so if a user searches for "bacon", they'll get a list of pizza options which they can go with which include that topping.
Is this even supported by Elasticsearch? I can separate out my results programmatically but I'm hoping it's built in.
Thanks for your time.