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 which returns wrong data
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "categories",
"query": {
"terms": {
"categories.id": [
9
]
}
}
}
},
{
"terms": {
"deleted": [
false
]
}
},
{
"terms": {
"published": [
true
]
}
},
{
"nested": {
"path": "vendors",
"query": {
"terms": {
"vendors.isDeletedVendor": [
false
]
}
}
}
},
{
"nested": {
"path": "vendors",
"query": {
"terms": {
"vendors.isPublishedVendor": [
true
]
}
}
}
}
],
"should": [
{
"bool": {
"must": [
{
"bool": {
"should": [
{
"bool": {
"must_not": [
{
"nested": {
"path": "manufacturers",
"query": {
"exists": {
"field": "manufacturers"
}
}
}
}
]
}
}
]
}
},
{
"bool": {
"should": [
{
"nested": {
"path": "vendors",
"query": {
"terms": {
"vendors.id": [
87
]
}
}
}
}
]
}
}
]
}
},
{
"bool": {
"must": [
{
"bool": {
"should": [
{
"bool": {
"must_not": [
{
"nested": {
"path": "manufacturers",
"query": {
"exists": {
"field": "manufacturers"
}
}
}
}
]
}
}
]
}
},
{
"bool": {
"should": [
{
"nested": {
"path": "vendors",
"query": {
"terms": {
"vendors.id": [
56
]
}
}
}
}
]
}
}
]
}
}
]
}
},
"size": 1000,
"_source": {
"includes": [
"modelName",
"vendors.id",
"manufacturers.id",
"id"
]
}
}
The logic of the query in should is like this
Select * from index where(manufacturers is null and vendorsid in(87)) or (manufacturers is null and vendorsidin(56)) but it gives me hits where manufacturers id are not null and vendors id are not in 87 or 56