I’m currently evaluating the Completion Suggester functionality in ElasticSearch to realize auto complete. It does look very decent so far. However I’m struggling a little bit with permissions.
Let’s assume I have an index with hotels like the example on the ElesticSearch website. Besides getting the hotels that match with the given phrase I also wanna check whether the user is allowed to see the "suggestion" or not. Something like hotels which are for a certain clientele only. I added a new field for saving the group/permission just as a simple string for testing purpose. What I want to accomplish is to filter by the groups.
The mapping would look something like that:
{
"mappings": {
"hotel" : {
"properties" : {
"name" : { "type" : "string" },
"city" : { "type" : "string" },
"group" : { "type" : "string" },
"name_suggest" : {
"type" : "completion",
"payloads" : true
}
}
}
}
}'
And with the following documents:
{
"name" : "Mercure Hotel Munich",
"city" : "Munich",
"group " : "1",
"name_suggest" : "Mercure Hotel Munich"
}'
{
"name" : "Monaco Hotel",
"city" : "Munich",
"group" : "2",
"name_suggest" : "Monaco Hotel"
}'
So, if a user with the group “1” is entering “M” he should only get "Mercure Hotel Munich". Vice versa, a user with group “2” is typing in “M” he should only get "Monaco Hotel ".
I’ve seen some similar posts on Stackoverflow regarding to Completion Suggester + filter and that it doesn’t work together.
In my honest opinion it’s not an unusual use case that some documents are for certain users. Therefore I don’t want to suggest anything which the user is not allowed to access.
So my question is: What is the best practice to accomplish this? I mean considering performance and maintainability regarding to upcoming ES versions.
Shall we stick with the edgeNGram solution until https://github.com/elasticsearch/elasticsearch/pull/4044 is integrated? Or is there another solution by using completion suggester?
TIA
As per version 1.2.0, you can add context to your suggester and obtain filtered suggestions.
Introductory blog post
Full Docs
Also see How can I add filter to Completion Suggester in ElasticSearch?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With