Im looking for some help with Aggregates in my query. Overall i got it running pretty for however it is excluding data and im maybe using the wrong approach here. In my dataset i have an key called “productwaarden” that is a nested object. Inside this i hold data like this:
Document 1:
[
{
"zoekbaar": false,
"waarde": "BOL",
"naam": "Leerweg",
"filterbaar": true
},
{
"zoekbaar": false,
"waarde": "2",
"naam": "Foo",
"filterbaar": true
}
]
Document 2:
[
{
"zoekbaar": false,
"waarde": "BBL",
"naam": "Leerweg",
"filterbaar": true
},
{
"zoekbaar": false,
"waarde": "1",
"naam": "Foo",
"filterbaar": true
}
]
The requirement i have is that when i filter on a naam with a waarde here. So for instance i select all BOL values. The aggregate should behave as an OR and not as an AND. The AND should be done over the naam key. For instance, when i select BOL as filter, both BOL and BBL should be in my aggregate result. When i select BOL only, the value for Foo should be only 2 since 1 is not matching on that document.
This is the query i have at this point:
{
"aggs": {
"productwaarden.nested": {
"nested": {
"path": "productwaarden"
},
"aggs": {
"productwaarden.filtered": {
"filter": {
"bool": {
"must": {
"term": {
"productwaarden.filterbaar": true
}
}
}
},
"aggs": {
"naam": {
"terms": {
"field": "productwaarden.naam.aggregate",
"size": 1000
},
"aggs": {
"waarde": {
"terms": {
"field": "productwaarden.waarde.aggregate",
"size": 1000
}
}
}
}
}
}
}
}
},
"query": {
"constant_score": {
"filter": {
"bool": {
"must": [
{
"nested": {
"path": "productwaarden",
"query": {
"bool": {
"must": [
{
"term": {
"productwaarden.naam.aggregate": "Leerweg"
}
},
{
"terms": {
"productwaarden.waarde.aggregate": ["BBL"]
}
}
]
}
}
}
}
]
}
}
}
}
}
Thanks in advance
Pim Jansen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.