This could be done with a filtered alias. The idea is that instead of searching via the index name you instead search via a filtered alias on that index. Here is an example. Let's say you have an index movies
with a type movie
. The most basic way of searching would be:
curl -XPOST localhost:9200/movies/movie/_search?q=...
When searching this way, you're basically giving access to the whole movie index. If you want to restrict access to only certain documents of that index to certain types of users, you can create an alias which will only query documents that match a certain filter, like this:
curl -XPOST localhost:9200/_aliases -d '{
"actions" : [
{
"add" : {
"index" : "movies",
"alias" : "disney_movies",
"filter" : { "term" : { "studio" : "disney" } }
}
}
]
}'
Then you can force the searches on that alias instead of on the index. Doing so will transparently only search movies with studio: disney
and you don't need to explicitely specify that in the query itself anymore.
curl -XPOST localhost:9200/disney_movies/movie/_search?q=...
If someone tries to tamper with the studio
variable, there will be no matching alias and hence no results coming back, which is what you want.