Mapping
PUT index
PUT /index/_mapping
{
"properties": {
"categories": {
"type": "nested",
"properties": {
"id": {
"type": "integer"
}
}
},
"deleted": {
"type": "boolean"
},
"id": {
"type": "long"
},
"manufacturers": {
"type": "nested",
"properties": {
"id": {
"type": "integer"
}
}
},
"vendors": {
"type": "nested",
"properties": {
"id": {
"type": "long"
},
"isDeletedVendor": {
"type": "boolean"
},
"isPublishedVendor": {
"type": "boolean"
}
}
},
"published": {
"type": "boolean"
}
}
}
Fill with Data
PUT index/_doc/1
{
"categories": [
{
"id": 9
}
],
"manufacturers": [
{
"id": 2452
}
],
"vendors": [
{
"id": 8,
"isDeletedVendor": true,
"isPublishedVendor": true
},
{
"id": 9,
"isDeletedVendor": true,
"isPublishedVendor": true
}
],
"published": true,
"deleted": false
}
Query
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "categories",
"query": {
"terms": {
"categories.id": [
9
]
}
}
}
},
{
"terms": {
"deleted": [
false
]
}
},
{
"terms": {
"published": [
true
]
}
},
{
"bool": {
"should": [
{
"nested": {
"path": "manufacturers",
"query": {
"terms": {
"manufacturers.id": [
2452
]
}
}
}
},
{
"bool": {
"must_not": [
{
"exists": {
"field": "manufacturers"
}
}
]
}
}
]
}
},
{
"bool": {
"should": [
{
"nested": {
"path": "vendors",
"query": {
"terms": {
"vendors.id": [
24
]
}
}
}
},
{
"bool": {
"must_not": [
{
"exists": {
"field": "vendors"
}
}
]
}
}
]
}
}
]
}
},
"_source": {
"includes": [
"vendors.id",
"manufacturers.id",
"id"
]
}
}
The Logic Should be something Like that:
Categories in values AND Deleted in False AND Published in True AND ManufacturerIds in values OR manufacturersIds not exist AND vendorIds in values OR vendorIds not exist
But sometimes it returns hits where manufacturers id is 10 or vendor id is 34 and so on...