# Results based on conditions from results themselves (yeah I know...)

**URL:** https://discuss.elastic.co/t/results-based-on-conditions-from-results-themselves-yeah-i-know/16805
**Category:** Elasticsearch
**Created:** [April 3, 2014, 7:52pm UTC](https://discuss.elastic.co/t/results-based-on-conditions-from-results-themselves-yeah-i-know/16805 "2014-04-03T19:52:29Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![mromagnoli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mromagnoli/32/839_2.png) [@mromagnoli](https://discuss.elastic.co/u/mromagnoli)
#### Post date: [April 3, 2014, 7:52pm UTC](https://discuss.elastic.co/t/results-based-on-conditions-from-results-themselves-yeah-i-know/16805/1 "2014-04-03T19:52:29Z")

</div>

Hi everybody,  
I'm having the next issue:

I was wondering if via scripting or another way, I could be able to discard  
documents retrieved based in results from the documents themselves (what!?).

I'll explain myself better:

Suppose I have a document indexed like:

```
      {
           "Review": {
              "body": "",
              "listing_id": 352755,
              "user_id": 4670,
              "title": "Bla",
              "message": "Blablabla bad service. ",
              "id": 263
           },
           "User": {
              "id": 4670,
              "first_name": "",
              "email": "example@example.com",
              "username": "example",
              "password": "123456"
           },
           "Listing": {
              "id": 352755,
              "user_id": 4670,
              "website_url": "",
              "zip_code": "3500",
              "description": "Bla bla many things"
           }
        }

```

Where I index \*Reviews \*from _Users_ made in \*Listings, \*but I don't want  
to retrieve those documents where field \*User.id == Listing.user\_id. \*But I  
don't know how to determine this condition when I want to dismiss a  
document based in a condition that lives inside it.  
Is there any way to cover this limitation?

Hope I was clear.

Thanks in advance!

Chelo (@mromagnoli)

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/affb14a1-c703-42b4-973d-b321e6cd99dc%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/affb14a1-c703-42b4-973d-b321e6cd99dc%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Binh\_Ly\_2](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Binh\_Ly\_2](https://discuss.elastic.co/u/Binh_Ly_2)
#### Post date: [April 3, 2014, 9:37pm UTC](https://discuss.elastic.co/t/results-based-on-conditions-from-results-themselves-yeah-i-know/16805/2 "2014-04-03T21:37:25Z")

</div>

Yes script filter can accomplish this but it could be very slow if you have  
lots documents. You can access the source in script using the \_source  
reference.

[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-script-filter.html#query-dsl-script-filter](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-script-filter.html#query-dsl-script-filter)

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c3fef509-5861-4b40-8a3c-ccd5c95044a4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c3fef509-5861-4b40-8a3c-ccd5c95044a4%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![mromagnoli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mromagnoli/32/839_2.png) [@mromagnoli](https://discuss.elastic.co/u/mromagnoli)
#### Post date: [April 4, 2014, 1:04pm UTC](https://discuss.elastic.co/t/results-based-on-conditions-from-results-themselves-yeah-i-know/16805/3 "2014-04-04T13:04:12Z")

</div>

I'm going to take a better look and see what happends.

Thx!!

El jueves, 3 de abril de 2014 18:37:25 UTC-3, Binh Ly escribió:

> Yes script filter can accomplish this but it could be very slow if you  
> have lots documents. You can access the source in script using the \_source  
> reference.
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-script-filter.html#query-dsl-script-filter)

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/bd6fbc60-72aa-4b0c-a9a2-cf4172187eba%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bd6fbc60-72aa-4b0c-a9a2-cf4172187eba%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![mromagnoli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mromagnoli/32/839_2.png) [@mromagnoli](https://discuss.elastic.co/u/mromagnoli)
#### Post date: [April 4, 2014, 2:31pm UTC](https://discuss.elastic.co/t/results-based-on-conditions-from-results-themselves-yeah-i-know/16805/4 "2014-04-04T14:31:50Z")

</div>

[SOLUTION]

As Binh suggest, I use script filter and was awesome, the query was:

{  
"query" : {  
"filtered": {  
"query" : {  
...  
}  
"filter": {  
"script": {  
"script": "doc['User.id'].value !=  
doc['Listing.user\_id'].value"  
}  
}  
}  
}  
}

El jueves, 3 de abril de 2014 16:52:29 UTC-3, @mromagnoli escribió:

> Hi everybody,  
> I'm having the next issue:
> 
> I was wondering if via scripting or another way, I could be able to  
> discard documents retrieved based in results from the documents themselves  
> (what!?).
> 
> I'll explain myself better:
> 
> Suppose I have a document indexed like:
> 
> ```
> {
> "Review": {
> "body": "",
> "listing_id": 352755,
> "user_id": 4670,
> "title": "Bla",
> "message": "Blablabla bad service. ",
> "id": 263
> },
> "User": {
> "id": 4670,
> "first_name": "",
> "email": "example@example.com",
> "username": "example",
> "password": "123456"
> },
> "Listing": {
> "id": 352755,
> "user_id": 4670,
> "website_url": "",
> "zip_code": "3500",
> "description": "Bla bla many things"
> }
> }
> 
> ```
> 
> Where I index \*Reviews \*from _Users_ made in \*Listings, \*but I don't want  
> to retrieve those documents where field \*User.id == Listing.user\_id. \*But  
> I don't know how to determine this condition when I want to dismiss a  
> document based in a condition that lives inside it.  
> Is there any way to cover this limitation?
> 
> Hope I was clear.
> 
> Thanks in advance!
> 
> Chelo (@mromagnoli)

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/f064a3c1-d426-4873-b8ba-4cf9ac198a89%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f064a3c1-d426-4873-b8ba-4cf9ac198a89%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:38am UTC](https://discuss.elastic.co/t/results-based-on-conditions-from-results-themselves-yeah-i-know/16805/5 "2017-07-06T01:38:06Z")

</div>


