I have an index with nested document structure as below -
{
"firstindex": {
"mappings": {
"properties": {
"Name": {
"type": "text"
},
"SecurityCodes": {
"type": "nested",
"properties": {
"Description": {
"type": "text"
},
"Name": {
"type": "text"
}
}
}
}
}
}
}
Here is how the docs look like -
{
"Name": "Doc1",
"SecurityCodes": [
{
"Name": "Restricted",
"Description": ""
},
{
"Name": "Unclassfied",
"Description": ""
}
]
},
{
"Name": "Doc2",
"SecurityCodes": [
{
"Name": "Restricted",
"Description": ""
},
{
"Name": "Restricted",
"Description": ""
}
]
},
{
"Name": "Doc3",
"SecurityCodes": [
{
"Name": "Restricted",
"Description": ""
},
{
"Name": "Unknown",
"Description": ""
}
]
}
all i want to do is to write a query that returns documents where each securitycode matches the condition.
for e.g. if the search string is Restricted (over secuirtycode.name) it should return doc2 but not doc1 and doc3 since each and every securitycode name matches Restricted under doc2
i tried this but it returns all the docs
"query": {
"nested": {
"path": "SecurityCodes",
"query": {
"bool": {
"must": [
{
"term": {
"SecurityCodes.Name": "Restricted"
}
}
]
}
}
}
}
i looked into the answer here but that is not acceptable since it requires a field to exist on the index and we have lot of such nested docs in our index and having a copy feild for each one is not acceptable.
can any one help me out please?