# Not equal to function

**URL:** <https://discuss.elastic.co/t/not-equal-to-function/81318>\
**Category:** Elasticsearch\
**Created:** [April 5, 2017, 1:56pm UTC](https://discuss.elastic.co/t/not-equal-to-function/81318 "2017-04-05T13:56:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raj\_Kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raj_kumar/32/25420_2.png) [@Raj\_Kumar](https://discuss.elastic.co/u/Raj_Kumar)\
**Post date:** [April 5, 2017, 1:56pm UTC](https://discuss.elastic.co/t/not-equal-to-function/81318/1 "2017-04-05T13:56:02Z")

</div>

Hi All,

I have a fields called subject.Account name and Target.account name , sometimes both have same values like

subject.Accountname : abc11  
subject,Targetname : abc11

sometimes both values will be different like,

subject.Accountname : xyz34  
subject.Targetname : abc12

Is it possible to right a query like Where Target Account name  
Is not EQUAL to Subject Account Name , i need to have the values of that alone.

Any help much appreciated 🙂

Thanks in advance,  
Raj

---

<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 5, 2017, 2:13pm UTC](https://discuss.elastic.co/t/not-equal-to-function/81318/2 "2017-04-05T14:13:48Z")

</div>

You can do it with a [`script`](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-script-query.html) query but it won't be able to use the index. If need to do this quickly then you should add a flag to the documents with the same accounts at ingest time. If you don't care about how slow the query is then go for the script query.

---

<div class="post-metadata">

**Author:** ![Raj\_Kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raj_kumar/32/25420_2.png) [@Raj\_Kumar](https://discuss.elastic.co/u/Raj_Kumar)\
**Post date:** [April 5, 2017, 2:20pm UTC](https://discuss.elastic.co/t/not-equal-to-function/81318/3 "2017-04-05T14:20:41Z")

</div>

thank you very much for the reply,do you have any example query for this , if possible 🙂

---

<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 5, 2017, 2:38pm UTC](https://discuss.elastic.co/t/not-equal-to-function/81318/4 "2017-04-05T14:38:43Z")

</div>

I don't have an example handy but it'd look something like:

```auto
POST /test/_search
{
  "query": {
    "script": {
      "inline": "doc['Accountname'].value == doc['Targetname'].value"
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Raj\_Kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raj_kumar/32/25420_2.png) [@Raj\_Kumar](https://discuss.elastic.co/u/Raj_Kumar)\
**Post date:** [April 5, 2017, 2:40pm UTC](https://discuss.elastic.co/t/not-equal-to-function/81318/5 "2017-04-05T14:40:36Z")

</div>

thank you Nick

---

<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:** [May 3, 2017, 2:40pm UTC](https://discuss.elastic.co/t/not-equal-to-function/81318/6 "2017-05-03T14:40:53Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
