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


(@mromagnoli) #1

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


(Binh Ly-2) #2

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

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


(@mromagnoli) #3

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.

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


(@mromagnoli) #4

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


(system) #5