Search nested objects using wildcard / multiple nested.path

Hello,

My question is somewhat similar to Search nested objects using wildcard paths? (asking again in case there were changes / updates).
We will be using ES 6.0.1.

Generally, we will have nested documents (e.g. list of attachments in an article) in our mapping. However we have some sort of data security for the nested objects (some users can only access attachments if they are allowed to) so we added a parent level for the nested object whose property name is some security code.
(where we can apply ES field level security to not return the nested security code property depending on user's roles e.g. if user doesn't have role that exposes property attachments.AB_0, then attachments.AB_0 is not returned which ES XPack can handle )

e.g sample mapping.
"properties": {
"article_name": {"type": "text"},
"attachments": {
"AB_0": {
"type": "nested",
"properties": {
"descrip": { "type": "text" },
"file_size": { "type": "long" }
}
},
"AB_1": {
"type": "nested",
"properties": {
"descrip": { "type": "text" },
"file_size": { "type": "long" }
}
},
"EX_0": {
"type": "nested",
"properties": {
"descrip": { "type": "text" },
"file_size": { "type": "long" }
}
}
...
}
}

Unfortunately, we seem to reach an issue in creating a search query on the nested object fields (e.g. searching on attachment description)

It seems the nested.path doesn't support wildcards (e.g path: "attachments.*") or array of paths (path: ["attachments.AB_0", "attachments.AB_1",...]) so currently it seems we have no choice but to do a bool query containing duplicate clauses with nested.path for each security code.

{"bool": {
"should":
[{
"nested": {
"path": "attachments.AB_0",
"query": {"query_string": { "fields": ["attachments..descrip"], "query" : "hello" } }
}
},
{
"nested": {
"path": "attachments.AB_1",
"query": {"query_string": { "fields": ["attachments.
.descrip"], "query" : "hello" } }
}
},
..
]
}
}

which we think will affect performance due to having a separate query for each security code.
Note that a user can have access to 1000+ security code combinations which will result to 1000+ queries in a bool query..

Any advice on how to construct a simpler search query (e.g. does nested.path support wildcard or multiple paths and we're just doing it wrong) or a better mapping to handle our requirement?

Thanks

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.