# Evaluating data against two fields

**URL:** <https://discuss.elastic.co/t/evaluating-data-against-two-fields/5544>\
**Category:** Elasticsearch\
**Created:** [October 8, 2011, 10:56pm UTC](https://discuss.elastic.co/t/evaluating-data-against-two-fields/5544 "2011-10-08T22:56:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Ferreira](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@Daniel\_Ferreira](https://discuss.elastic.co/u/Daniel_Ferreira)\
**Post date:** [October 8, 2011, 10:56pm UTC](https://discuss.elastic.co/t/evaluating-data-against-two-fields/5544/1 "2011-10-08T22:56:21Z")

</div>

I'm very new in elasticsearch and I think this is a really powerful tool.  
In my project I need to perform a query where the two or more fields may be correlated.  
In order to solve this problem I have used scripting and created the next solution:

curl -XPOST '[http://localhost:9200/my\_index/\_search?pretty=true](http://localhost:9200/my_index/_search?pretty=true)' -d '{  
"query":{  
"custom\_score" : {  
"query" : {  
"query\_string" : {  
"query" : "\*"  
}  
},  
"script" : "\_score = \_source.field1 != \_source.field2 ? 1 : -1;"  
}  
},  
"min\_score": 0.0  
}'

I'm wondering if there are a more efficient manner to perform the same type of query and if  
the community can point me a direction?

Thank you in advance.

---

<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:52am UTC](https://discuss.elastic.co/t/evaluating-data-against-two-fields/5544/2 "2017-07-06T03:52:31Z")

</div>

Closed on July 6, 2017, 3:52am UTC


