Maybe somebody has implemented such a search in nested documents.
Here is my mapping:
{
"my-index": {
"aliases": {},
"mappings": {
"properties": {
"customer": {
"type": "nested",
"properties": {
"id": {
"type": "keyword"
},
"name": {
"type": "text"
}
}
},
"id": {
"type": "keyword"
},
"items": {
"type": "nested",
"properties": {
"id": {
"type": "keyword"
},
"name": {
"type": "text"
}
}
},
"number": {
"type": "text"
}
}
}
}
}
There is the search text like "Number CustomerName ItemName". But each of the fields is optional.
And here is my query:
{
"query": {
"bool": {
"should": [
{
"match": {
"number": "5785 SomeCustomerName SomeItemName"
}
},
{
"nested": {
"path": "customer",
"query": {
"bool": {
"must": [
{
"match": {
"customer.name": {
"query": "5785 SomeCustomerName SomeItemName",
"operator": "and"
}
}
}
]
}
},
"inner_hits": {}
}
},
{
"nested": {
"path": "items",
"query": {
"bool": {
"must": [
{
"match": {
"items.name": {
"query": "5785 SomeCustomerName SomeItemName",
"operator": "and"
}
}
}
]
}
},
"inner_hits": {}
}
}
]
}
}
}
But if the operator is "and" I find nothing. If the operator is "or" I find too many documents where they contain one of these words.
How do I set up this flexible search?