# Compare properties

**URL:** <https://discuss.elastic.co/t/compare-properties/475>\
**Category:** Elasticsearch\
**Created:** [May 11, 2015, 6:57am UTC](https://discuss.elastic.co/t/compare-properties/475 "2015-05-11T06:57:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![apk](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@apk](https://discuss.elastic.co/u/apk)\
**Post date:** [May 11, 2015, 6:57am UTC](https://discuss.elastic.co/t/compare-properties/475/1 "2015-05-11T06:57:38Z")

</div>

Hi,  
i'm quiet new to elasticsearch and i wonder if it is possibile to write a query to get all types where type1.name = typ2.name?

Any hints about that?

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [May 11, 2015, 7:37am UTC](https://discuss.elastic.co/t/compare-properties/475/2 "2015-05-11T07:37:25Z")

</div>

You could use a script filter but this would be very slow as script filters cannot leverage the inverted index. For such queries, the best option is to pre-compute this kind of information at indexing time (`"is_type1_equal_to_type2": true`) so that you can later use simple term queries to find documents you are interested in.

---

<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:** [May 11, 2015, 2:15pm UTC](https://discuss.elastic.co/t/compare-properties/475/3 "2015-05-11T14:15:30Z")

</div>

I suspect its possible to do much better by implementing a new query as a  
plugin. It'd parallel walk the terms dictionary. But Elasticsearch doesn't  
have a query for that already implemented and exposed.

The script approach is best if you aren't going to do it much. The  
precomputed approach for when you only have a couple of these fields and  
are willing to reindex. I'd go with a flags style field, not\_analyzed with  
array of flags for the fields that are the same.

The new query way is much more to learn and code but could be more flexible  
if you have lots of fields.

You could use all three methods to handle stuff like `_source.a == _source.b + 10`.

Finding too documents with the same value in a field pairwise would be much  
much harder.  
Nik

---

<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, 12:14am UTC](https://discuss.elastic.co/t/compare-properties/475/4 "2017-07-06T00:14:38Z")

</div>


