How would you search an index in Elastic Search that would include different matching indexes/entities along with it. I need to have complex search suggestions, they need to be grouped per entity. An image speaks a thousand words, so the following image describes pretty much what I want to achieve:
How should I model my indexes to achieve the above?
Right now my order
index looks like this:
{
"_index": "mango",
"_type": "order",
"_id": "4",
"_score": 1,
"_source": {
"number": "000000004",
"customer": {
"id": 14,
"firstName": "Jean",
"lastName": "Hermann",
"email": "lucinda90@example.com"
}
}
}
And when I do a search with the text example.com
I need a response, that looks somewhat like (left out hits
to be more readable):
{
"hits": {
"hits": []
}
"aggregations": {
"customers": [
{
"id": 1,
"firstName": "Mille",
"lastName": "VonRueden",
"email": "shickle@example.com"
},
{
"id": 2,
"firstName": "Clint",
"lastName": "Effertz",
"email": "briana91@example.com"
}
]
}
}
How would my search query look like to achieve such response?
I have tried to use the following search query, but it just returns an empty bucket:
{
"size": 1,
"aggs": {
"customers": {
"nested": {
"path": "customer"
},
"aggs": {
"name": {
"terms": {
"field": "customer.id"
}
}
}
}
}
}
This is the mapping of my order index (in YAML format):
order:
mappings:
number: ~
createdAt:
type: date
customer:
type: nested
properties:
id :
type : integer
index: not_analyzed
firstName:
type: string
index: not_analyzed