# Right tool for the job?

**URL:** <https://discuss.elastic.co/t/right-tool-for-the-job/47030>\
**Category:** Elasticsearch\
**Created:** [April 11, 2016, 7:05pm UTC](https://discuss.elastic.co/t/right-tool-for-the-job/47030 "2016-04-11T19:05:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dom2497](https://avatars.discourse-cdn.com/v4/letter/d/bc79bd/32.png) [@dom2497](https://discuss.elastic.co/u/dom2497)\
**Post date:** [April 11, 2016, 7:05pm UTC](https://discuss.elastic.co/t/right-tool-for-the-job/47030/1 "2016-04-11T19:05:56Z")

</div>

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...

Person  
Name  
Age  
Sex  
Interests  
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.

Thanks

Dom

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [April 11, 2016, 7:28pm UTC](https://discuss.elastic.co/t/right-tool-for-the-job/47030/2 "2016-04-11T19:28:08Z")

</div>

This comes up from time to time. [Matching by array elements](https://discuss.elastic.co/t/matching-by-array-elements/39530) has a pretty good discussion on it.

---

<div class="post-metadata">

**Author:** ![dom2497](https://avatars.discourse-cdn.com/v4/letter/d/bc79bd/32.png) [@dom2497](https://discuss.elastic.co/u/dom2497)\
**Post date:** [April 12, 2016, 9:38am UTC](https://discuss.elastic.co/t/right-tool-for-the-job/47030/3 "2016-04-12T09:38:22Z")

</div>

Thanks, I will have a read 🙂

---

<div class="post-metadata">

**Author:** ![dom2497](https://avatars.discourse-cdn.com/v4/letter/d/bc79bd/32.png) [@dom2497](https://discuss.elastic.co/u/dom2497)\
**Post date:** [April 12, 2016, 10:31am UTC](https://discuss.elastic.co/t/right-tool-for-the-job/47030/4 "2016-04-12T10:31:06Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:00pm UTC](https://discuss.elastic.co/t/right-tool-for-the-job/47030/5 "2017-07-05T23:00:15Z")

</div>


