# Comparing two numeric fields of a Document

**URL:** <https://discuss.elastic.co/t/comparing-two-numeric-fields-of-a-document/9796>\
**Category:** Elasticsearch\
**Created:** [November 22, 2012, 7:21pm UTC](https://discuss.elastic.co/t/comparing-two-numeric-fields-of-a-document/9796 "2012-11-22T19:21:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rahul\_Sharma](https://avatars.discourse-cdn.com/v4/letter/r/df705f/32.png) [@Rahul\_Sharma](https://discuss.elastic.co/u/Rahul_Sharma)\
**Post date:** [November 22, 2012, 7:21pm UTC](https://discuss.elastic.co/t/comparing-two-numeric-fields-of-a-document/9796/1 "2012-11-22T19:21:17Z")

</div>

Hi,

Is it possible to compare 2 numeric fields of a document?  
I want to fire a search query where I want to achieve n1 \> n2, where n1 and  
n2 are numeric terms of an Index.

Would really appreciate your help.

Thanks  
Rahul.

--

---

<div class="post-metadata">

**Author:** ![Chris\_Male](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_male/32/2607_2.png) [@Chris\_Male](https://discuss.elastic.co/u/Chris_Male)\
**Post date:** [November 23, 2012, 12:23am UTC](https://discuss.elastic.co/t/comparing-two-numeric-fields-of-a-document/9796/2 "2012-11-23T00:23:21Z")

</div>

Hi Rahul,

It's not really possible to do it with traditional query syntaxes  
but [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/script-filter.html)  
should be sufficient.

On Friday, November 23, 2012 8:21:24 AM UTC+13, Rahul Sharma wrote:

> Hi,
> 
> Is it possible to compare 2 numeric fields of a document?  
> I want to fire a search query where I want to achieve n1 \> n2, where n1  
> and n2 are numeric terms of an Index.
> 
> Would really appreciate your help.
> 
> Thanks  
> Rahul.

--

---

<div class="post-metadata">

**Author:** ![Rahul\_Sharma](https://avatars.discourse-cdn.com/v4/letter/r/df705f/32.png) [@Rahul\_Sharma](https://discuss.elastic.co/u/Rahul_Sharma)\
**Post date:** [November 23, 2012, 8:13am UTC](https://discuss.elastic.co/t/comparing-two-numeric-fields-of-a-document/9796/3 "2012-11-23T08:13:46Z")

</div>

Thanks Chris for the response.

This solves my problem. But not sure how it really works. Does it translate  
to lucene queries internally or filters works outside of it at reducer  
level.  
Will run some performance test.

Any of you have used this feature, would love to hear.

Thanks  
Rahul

On Fri, Nov 23, 2012 at 5:53 AM, Chris Male [gento0nz@gmail.com](mailto:gento0nz@gmail.com) wrote:

> Hi Rahul,
> 
> It's not really possible to do it with traditional query syntaxes but  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/script-filter.htmlshould) be sufficient.
> 
> On Friday, November 23, 2012 8:21:24 AM UTC+13, Rahul Sharma wrote:
> 
> > Hi,
> > 
> > Is it possible to compare 2 numeric fields of a document?  
> > I want to fire a search query where I want to achieve n1 \> n2, where n1  
> > and n2 are numeric terms of an Index.
> > 
> > Would really appreciate your help.
> > 
> > Thanks  
> > Rahul.
> 
> --

--

---

<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, 3:03am UTC](https://discuss.elastic.co/t/comparing-two-numeric-fields-of-a-document/9796/4 "2017-07-06T03:03:12Z")

</div>


