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": [
{
"bool": {
"minimum_should_match": 1,
"should": [
{
"nested": {
"path": "vendors",
"query": {
"terms": {
"vendors.id": [
24
]
}
}
}
},
{
"bool": {
"must_not": [
{
"nested": {
"path": "vendors",
"query": {
"exists": {
"field": "vendors.id"
}
}
}
}
]
}
}
]
}
},
{
"bool": {
"minimum_should_match": 1,
"should": [
{
"nested": {
"path": "manufacturers",
"query": {
"terms": {
"manufacturers.id": [
2452
]
}
}
}
},
{
"bool": {
"must_not": [
{
"nested": {
"path": "manufacturers",
"query": {
"exists": {
"field": "manufacturer.id"
}
}
}
}
]
}
}
]
}
}
]
}
},
"size": 10000,
"_source": {
"includes": [
"deleted",
"published",
"vendors.id",
"categories.id",
"manufacturers.id",
"id"
]
}
}
so what I have in query logic is: GET hits where (
[
[manufacturer ids in 2452 or
manucaturerids not exist ] AND
[vendorids in 24 or
vendorids not exist]
]
)
Query works perfect but i want logic like this
GET hits where (
[
[manufacturer ids in 2452 or
manucaturerids not exist ] AND
[vendorids in 24 or
vendorids not exist]
]
OR
[
[manufacturer ids in 3 or
manucaturerids not exist ] AND
[vendorids in 9 or
vendorids not exist]
]
)
I was trying something like this but it didn't worked... pls help...
{
"query": {
"bool": {
"must": [
{
{
"bool": {
"minimum_should_match": 1,
"should": [
{
"nested": {
"path": "vendors",
"query": {
"terms": {
"vendors.id": [
24
]
}
}
}
},
{
"bool": {
"must_not": [
{
"nested": {
"path": "vendors",
"query": {
"exists": {
"field": "vendors.id"
}
}
}
}
]
}
}
]
}
},
{
"bool": {
"minimum_should_match": 1,
"should": [
{
"nested": {
"path": "manufacturers",
"query": {
"terms": {
"manufacturers.id": [
2452
]
}
}
}
},
{
"bool": {
"must_not": [
{
"nested": {
"path": "manufacturers",
"query": {
"exists": {
"field": "manufacturer.id"
}
}
}
}
]
}
}
]
}
}
},
{
{
"bool": {
"minimum_should_match": 1,
"should": [
{
"nested": {
"path": "vendors",
"query": {
"terms": {
"vendors.id": [
9
]
}
}
}
},
{
"bool": {
"must_not": [
{
"nested": {
"path": "vendors",
"query": {
"exists": {
"field": "vendors.id"
}
}
}
}
]
}
}
]
}
},
{
"bool": {
"minimum_should_match": 1,
"should": [
{
"nested": {
"path": "manufacturers",
"query": {
"terms": {
"manufacturers.id": [
3
]
}
}
}
},
{
"bool": {
"must_not": [
{
"nested": {
"path": "manufacturers",
"query": {
"exists": {
"field": "manufacturer.id"
}
}
}
}
]
}
}
]
}
}
},
]
}
},
"size": 10000,
"_source": {
"includes": [
"deleted",
"published",
"vendors.id",
"categories.id",
"manufacturers.id",
"id"
]
}
}