Right tool for the job?

Hi gang, my first time posting so hopefully I am in the right place. I am working on a little project mainly to get to grips with Elastic Search and I have hit a stumbling block and I was looking for some advice.

I am starting to ask myself am I using the right tool for the job as I cannot seem to find a way of solving the problem - however this could just be due to my inexperience.

Anyway, here is the problem I have....

So I have a document which contains a array of objects which have a bunch of properties. I would like to be able to chuck a list of terms at ES and it returns any documents whose inner array property matches. The next bit is the bit I am getting stuck on, I want to filter the documents so that only documents whose array is fully matched the search terms are returned. Its doesnt matter if the documents array contents is a subset of the search terms but all of the arrays contents must be matched. Hope I have managed to describe that well enough!

As a example:

I have a person document with some properties and a inner array of interests which also have a load of properties...

Name (property of a interest)
Category (property of a interest)
Some other property (property of a interest)
another property (property of a interest)

So say I have a guy called Bob, he likes squash, fishing and tennis. And I have another guy called Fred, he likes squash, fishing, tennis and football. And finally I have a guy called Jim, he likes fishing and tennis.

Now if I search for fishing, tennis and squash I want Bob and Jim to be returned because everything in their array matched the search terms even though Jim's was only a subset. Fred does not get returned because he likes foodball which wasent in the search terms.

Could anyone help or point me in the right direction of how I can achieve this, I have looked into scripted filteres however I cannot seem to find enough detail to achieve the desired behavior.



This comes up from time to time. Matching by array elements has a pretty good discussion on it.

Thanks, I will have a read :slight_smile:

I have had a read through the discussion there and it gives me some really good info. I guess the problems that I face are that the array contents are not enumerated values as such - the example I have given above is more a representation of what I have trying to solve.

I have added a field to the person which is a interests count, so for bob this would be 3 and for Jim it would be 2.

I also went down a avenue of tweaking the scoring so that the score for each document was effectively how many matches in the array the the document hit in relation to the search query. I was hoping I could then use this in the filter script, but I cant find a way of getting hold of a documents score value in the filter script context? If I can get that I can solve this.

So distilling this down a bit to one simple question - is there a way of getting hold of a documents score value in the filter script context?