I am trying to query a certain type of documents in my index.
Let's see the following document:
{
"id": 1,
"title": "My first Collection",
"items": [
{
"code": "SB",
"order": 1,
"random": "something random"
},
{
"code": "BB",
"order": 2,
"random": "something random"
},
{
"code": "FO",
"order": 3,
"random": "something random"
},
{
"code": "RA",
"order": 4,
"random": "something random"
},
{
"code": "FO",
"order": 5,
"random": "something random"
}
]
}
The items
field is a nested
field.
I would like to query all the articles that matches the exact pattern:
{
"items": [
{
"code": "SB",
"order": 1
},
{
"code": "BB",
"order": 2
},
{
"code": "FO",
"order": 3
},
{
"code": "RA",
"order": 4
}
]
}
The queried documents would have all those 4 items with this exact combination of fields. But they could have more too. The described document above would match the query.
I searched through the entire documentation, particularly in the nested queries part and I did not find any way to get it working.
Is it even possible or should I implement my own algorithm/script?
EDIT:
I tried the following without success:
{
"query": {
"nested": {
"path": "items",
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "items.code:SB AND items.order:1"
}
},
{
"query_string": {
"query": "items.code:BB AND items.order:2"
}
},
{
"query_string": {
"query": "items.code:FO AND items.order:3"
}
}
]
}
}
}
}
}