# Matching documents against each other on specified properties instead of a search term

**URL:** <https://discuss.elastic.co/t/matching-documents-against-each-other-on-specified-properties-instead-of-a-search-term/13299>\
**Category:** Elasticsearch\
**Created:** [August 22, 2013, 1:17pm UTC](https://discuss.elastic.co/t/matching-documents-against-each-other-on-specified-properties-instead-of-a-search-term/13299 "2013-08-22T13:17:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Brown](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_brown/32/2144_2.png) [@Alex\_Brown](https://discuss.elastic.co/u/Alex_Brown)\
**Post date:** [August 22, 2013, 1:17pm UTC](https://discuss.elastic.co/t/matching-documents-against-each-other-on-specified-properties-instead-of-a-search-term/13299/1 "2013-08-22T13:17:27Z")

</div>

Instead of searching for a query, Is there a way of comparing documents  
against one another?

For example, let's imagine a domain where each member has a 'profile'  
Each profile has many key:value pairs, like:

favourite\_color: "Blue"  
favourite\_food: "Pizza"  
favourite\_place: "Beach"

Further document structure example:

id: 1  
name: John Smith  
favourite\_color: Blue  
favourite\_food: Pizza  
other\_value: Some Value

id: 2  
name: Sarah Jones  
favourite\_color: Green  
favourite\_food: Chinese  
birthday\_month: June  
other\_value: Whatever

id: 3  
name: Andy Green  
favourite\_color: Blue  
favourite\_food: Pizza  
other\_value: Other Value  
birthday\_month: June

id: 4  
name: Simon  
favourite\_color: Blue  
favourite\_food: Pizza  
other\_value: Other Value  
birthday\_month: May

I'd like to be able to pass in a query such as:

"return all the documents where favourite\_colour and favourite\_place match"

In the above example, 1, 3 and 4 would be returned.

another query may be:

"return all the documents where favourite\_colour and favourite\_place match  
BUT where other\_value DO NOT match"  
In the above example, 1 and 3 would be returned. 4 would not, since  
other\_value matches with 3

Is that possible with ElasticSearch?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 6, 2017, 2:20am UTC](https://discuss.elastic.co/t/matching-documents-against-each-other-on-specified-properties-instead-of-a-search-term/13299/2 "2017-07-06T02:20:10Z")

</div>


